本文介绍了geg_line()在ggplot()中的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用ggplot()来显示数据的均值和方差,但我不知道为什么,尽管我已经使用geom_line(),但根据实验,结果并未作为线连接。
数据框仅仅是一个例子,如果它很奇怪,那么很抱歉。

  dfc 
m1 s1 sd1.5 sd1.10 sd1.15 sd1.20 sd1.25 sd1.30
1 10 n = 4 1实验1 15 20 25 30
2 12 n = 8 1实验1 15 20 25 30
3 14 n = 12 2实验1 15 20 25 30
4 13 n = 4 1实验2 15 20 25 30
5 16 n = 8 2实验2 15 20 25 30
6 19 n = 12 1实验2 15 20 25 30

ggplot(dfc ,aes(x = s1,y = m1,color = sd1.10))+
geom_errorbar(aes(ymin = m1-sd1.5,ymax = m1 + sd1.5),width = 0.1)+
geom_line()+
geom_point()


非常感谢

aes(group = sd1.10)添加到 geom_line 即可解决问题。 $ c $>告诉 ggplot 哪些点属于一个组:

  ggplot(dfc,aes(x = s1,y = m1,color = sd1.10))+ 
geom_errorbar(aes(ymin = m1-sd1.5,ymax = m1 + sd1.5),width = 0.1)+
geom_line(aes(group = sd1.10))+
geom_point()

I have used the ggplot() to show the mean and variance of my data but I do not know why although I have used geom_line() the result is not connected as a line according to the experiment.The data frame is just an example sorry if it is weird.

dfc
  m1   s1 sd1.5      sd1.10 sd1.15 sd1.20 sd1.25 sd1.30
1 10  n=4     1 experiment1     15     20     25     30
2 12  n=8     1 experiment1     15     20     25     30
3 14 n=12     2 experiment1     15     20     25     30
4 13  n=4     1 experiment2     15     20     25     30
5 16  n=8     2 experiment2     15     20     25     30
6 19 n=12     1 experiment2     15     20     25     30

ggplot(dfc, aes(x=s1,y=m1,colour=sd1.10)) + 
  geom_errorbar(aes(ymin=m1-sd1.5,ymax=m1+sd1.5),width=0.1)+
  geom_line()+
  geom_point()

many thanks

解决方案

Just add aes(group = sd1.10) to geom_line to tell ggplot which points belong to one group:

ggplot(dfc, aes(x=s1,y=m1,colour=sd1.10)) + 
  geom_errorbar(aes(ymin=m1-sd1.5,ymax=m1+sd1.5),width=0.1)+
  geom_line(aes(group = sd1.10))+
  geom_point()

这篇关于geg_line()在ggplot()中的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 02:25