绘图意味着用ggplot绘制散点图上的线图 [英] Plotting means as a line plot onto a scatter plot with ggplot
问题描述
我有这个简单的数据框,为每个因子(CT)保存三个重复值(值)。我想将它绘制成geom_point,而不是以geom_line的形式表示。
gene <-c(Ckap5 , Ckap5, Ckap5, Ckap5, Ckap5, Ckap5, Ckap5, Ckap5, Ckap5, Ckap5, Ckap5, Ckap5, Ckap5, (0.86443,0.79032,0.86517,0.779782,0.79439,0.89221,0.93071,0.87170,0.86488,0.91133,0.87202,0.84028,0.83242,0.74016,0.86656)$ b(Ckap5,Ckap5)
值<-c $ b CT <-c(ET,ET,ET,HP,HP,HP,HT,HT,HT,LT,LT ,LT,P,P,P)
df < - cbind(gene,value,CT)
df < - data.frame(df)
所以,我可以制作散点图。
<$ p $ b
$ g
我如何获得代表每个因子平均值的geom_line。我已经尝试了stat_summary:
$ g $ p $ g $ p $ ggplot(df,aes(x = CT,y = value))+ geom_point()+
stat_summary(aes(y = value,group = CT),fun.y = mean,color =red,geom =line)
但它不起作用。
geom_path:每组仅包含一个观察值,您是否需要调整组审美?
但每组有三个观察值,哪些是错误的?
Ps。
$ c $ = 1:$ pre $ g $ pggplot(df,aes(x = CT,y = value))+ geom_point()+
stat_summary(aes(y = value,group = 1),fun.y = mean,color =red,geom =line,group = 1)
p>
I have this simple data frame holding three replicates (value) for each factor (CT). I would like to plot it as geom_point and than the means of the point as geom_line.
gene <- c("Ckap5","Ckap5","Ckap5","Ckap5","Ckap5","Ckap5","Ckap5","Ckap5","Ckap5","Ckap5","Ckap5","Ckap5","Ckap5","Ckap5","Ckap5")
value <- c(0.86443, 0.79032, 0.86517, 0.79782, 0.79439, 0.89221, 0.93071, 0.87170, 0.86488, 0.91133, 0.87202, 0.84028, 0.83242, 0.74016, 0.86656)
CT <- c("ET","ET","ET", "HP","HP","HP","HT","HT","HT", "LT","LT","LT","P","P","P")
df<- cbind(gene,value,CT)
df<- data.frame(df)
So, I can make the scatter plot.
ggplot(df, aes(x=CT, y=value)) + geom_point()
How do I get a geom_line representing the means for each factor. I have tried the stat_summary:
ggplot(df, aes(x=CT, y=value)) + geom_point() +
stat_summary(aes(y = value,group = CT), fun.y=mean, colour="red", geom="line")
But it does not work. "geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?"
But each group has three observations, what is wrong?
Ps. I am also interested in a smooth line.
You should set the group aes
to 1:
ggplot(df, aes(x=CT, y=value)) + geom_point() +
stat_summary(aes(y = value,group=1), fun.y=mean, colour="red", geom="line",group=1)
这篇关于绘图意味着用ggplot绘制散点图上的线图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!