This question already has answers here:
Shading a kernel density plot between two points.
(5 answers)
Closed 5 years ago.
I've used the following to plot a Weibull distribution W(2,3):
Weibull=function(x){
(2*x/9)*exp(-(x^2)/9)
}
xx=seq(from=0,to=10,length.out=1000)
xx1=Weibull(xx)
plot(xx,xx1,type="l")
polygon(xx, xx1, col = "red", border = NA)
PDF plot
I want to shade the region between (4,10) only. How would I go about doing this?
xx2=seq(from=4,to=10,length.out=1000)
yy2=c(Weibull(xx2),0)
xx2=c(xx2,4)
plot(xx,xx1,type="l")
polygon(xx2, yy2, col = "red", border = NA)
Related
This question already has answers here:
R legend pch mix of character and numeric
(5 answers)
Closed 3 years ago.
Stuck getting my simple legend to print the proper symbols, the first needs to be a square which is pch 15, the second needs to be "#"
[square] y=x^2
[hashtag] y=1-x^2
legend("topright", legend=c("y=x^2", "y=1-x^2"),
col=c("red", "blue"),cex=1,pch=c(15,"#"))
Now what is happening the legend sees 1 then 5 where it should be a square & the hashtag, what am I doing wrong?
An approach would be to repeat the legend two times while changing one of them to missing value (NA)
plot(1, 1)
sapply(list(c(15, NA), c(NA, "#")), function(x)
legend("topright", legend = c("y=x^2", "y=1-x^2"),
col=c("red", "blue"),cex=1, pch = x))
This question already has an answer here:
Reduce size of legend area in barplot
(1 answer)
Closed 4 years ago.
I was trying to create a chart using below code in R:
myplot<-function(data,rows,Colm){
Data<-data[rows,Colm,drop=F]
matplot(t(Data), type = "b", pch=15:18, col = c(1:4, 6))
legend("bottomleft",inset = 0.01, legend = Players[rows],col = c(1:4, 6),
pch=15:18, horiz = F)
}
myplot(Games)
and got the below plot:enter image description here
Can anyone help me how to reduce the legend size?
The answer can be found here: Reduce size of legend area in barplot
The key is the cex argument in the legend function call.
The default is the equivalent of 1. Larger than the default size is greater than 1. From your question, you probably want to put the value as .5 and experiment from there until it is the size you want.
This question already has answers here:
Overlay normal curve to histogram in R
(4 answers)
Closed 4 years ago.
I am supposed to draw an overlay normal curve over a histogram in R. I am using the following code.
g <- unesco$Infant.Deaths
hist(g)
lines(seq(0, 200, by=5), dnorm(seq(0, 200, by=5),
mean(g), sd(g)), col="blue")
But instead of a curve, I am getting a straight line
It can be, that your histogram is representing frequencies instead of probability densities. Try to use hist(g, freq = FALSE).
This question already has an answer here:
Manually defining the colours of a wireframe
(1 answer)
Closed 4 years ago.
Is there a way to change the drape color scale in lattice: wireplot? I have a series of plots and would like to adjust the colors so they each show the same color scale. I am able to change the z axis scale, but that only makes it so the surface itself moves up and down, not the color scale. Is there a keyword I am missing when looking it up?
wireframe(InitFe2solid.ug.gdw~Depth*Distance,
allplatesdata[allplatesdata$UseMonth=="August", ],
drape = TRUE,
colorkey = TRUE,
zlab = list("Sulfate uM", rot = 90),
zlim = range(seq(0.0, 4)))
Adding the line fixes it
at=do.breaks(c(0,14),100)
This question already has answers here:
Extract regression coefficient values
(4 answers)
Closed 6 years ago.
I have plotted the scatter plot below using the following scripts but still need to obtain the regression coefficient.
Any help would be very much appreciated.
lm.irt12 <- lm(prtemp ~ irt12,data=apirt)
summary(lm.irt12)
plot(apirt$irt12[apirt$surv==1],
apirt$prtemp[apirt$surv==1],
xlab="ave. base of ears (°C)",
ylab="rectal (°C)",
xlim=c(26,42),
ylim=c(30,42),
col='blue')
points(apirt$irt12[apirt$surv==0], apirt$prtemp[apirt$surv==0],col='red')
abline(lm.irt12)
abline(h=36,v=0, col="gray10",lty=20)
#col = "gray60" OR col = "lightgray", lty=3; #(lty=3: broken line, 1:continuous)
text(26.7,36.7,parse(text='36*degree'),col='gray10')
abline(h=34,v=0, col="gray10",lty=20)
#col = "gray60" OR col = "lightgray", lty=3; #(lty=3: broken line, 1:continuous)
text(26.7,34.7,parse(text='34.0*degree'),col='gray10')
You just have to get the coefficient parameter of your linear model object lm.irt12:
lm.irt12$coefficients
To see the parameter of R objects, you can do:
str(lm.irt12)