r - excluding new layer from scale_size -
i have plotted scatter plot point size scaled frequency:
g<-ggplot(d, aes(x=treatment, y= seam.cell.number, size=frequency))+geom_point(aes(colour=strain))+ scale_size_continuous(range = c(3, 10), breaks=c(0,1, 2, 3, 4, 5,6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50))+guides(size=false)
now trying plot means standard error bars on top. have mean , standard error calculated in columns in csv file. so far have attempted:
g+geom_point(aes(x=treatment,y=mean))+geom_errorbar(aes(ymin=mean-standard.error, ymax=mean+standard.error, width=.4))+theme(axis.text.x = element_blank())+theme(legend.key = element_rect(colour = "black"))
and:
g+layer(data=d, mapping=aes(x=treatment,y=mean), geom="point")+geom_errorbar(aes(ymin=mean-standard.error, ymax=mean+standard.error), width=.4)+ylab("seam cell number")
but both give me fat error bars/data points. seems being affected size scaling in object g. have tried modify size , width of error bars, , have tried modify size of data points, both in these last bits of code, no avail. there way 'cancel' size command layer?
if reverse order of ggplot, may able avoid size distortion on error bars.
not having reproducible data, made up.
df <- data.frame(treatment = (1:100), seam.cell.number = 3:102, frequency = 5:104, strain = rep(c("a", "b", "c", "d"), 25)) std <- function(x) sd(x)/sqrt(length(x)) mean <- mean(df$treatment) df$standard.error <- std(df$treatment) g <- ggplot(df, aes(x = treatment, y = seam.cell.number)) + geom_point(aes(x=treatment, y=mean)) + geom_errorbar(aes(ymin=mean-df$standard.error, ymax=mean+df$standard.error, width=.4))+ theme(axis.text.x = element_blank())+ theme(legend.key = element_rect(colour = "black")) g + geom_point(aes(colour=strain)) + scale_size_continuous(range = c(3, 10), breaks=c(0,1, 2, 3, 4, 5,6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50)) + guides(size=false)
Comments
Post a Comment