Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用GGR中的ggplot将多组数据放在一个图形上_R - Fatal编程技术网

如何使用GGR中的ggplot将多组数据放在一个图形上

如何使用GGR中的ggplot将多组数据放在一个图形上,r,R,我知道这个问题已经被问过很多次了,但我认为因为我使用了其他元素(比如geom_smooth),这对我来说不起作用。我试着把三组数据画在一张图上 数据框与此类似(例如,我无法提供此私有数据集的值): 这是三个数据集之一的代码 plot <- data [data$group == "Control", ] p <- ggplot (plot, aes(x, y)) + geom_point(shape= 21, fill= "blue", colour= "black", size

我知道这个问题已经被问过很多次了,但我认为因为我使用了其他元素(比如
geom_smooth
),这对我来说不起作用。我试着把三组数据画在一张图上

数据框与此类似(例如,我无法提供此私有数据集的值):

这是三个数据集之一的代码

plot <- data [data$group == "Control", ]
p <- ggplot (plot, aes(x, y)) +
  geom_point(shape= 21, fill= "blue", colour= "black", size=2) +
  geom_smooth(method= "lm", se= FALSE,  colour= "red", formula=y ~ poly(x, 3, raw=TRUE)) +
  geom_errorbar(aes(ymin=y-SE, ymax=y+SE), width=.9)
p
绘图

  • 使用
    绘图,谢谢!我知道这很简单:)我的另一个问题是如何使线条有不同的颜色?它们都显示为红色。@Purrina,您使用的是
    color=“red”
    ,为什么线条不应该是红色的呢?考虑阅读关于<代码> GGPrP>代码>的介绍性文本,例如@ Purrina,好极了!在中,通过在
    aes
    参数中添加
    color=分组变量的名称,可以将行的颜色“映射”到特定变量。祝你好运
    
    plot <- data [data$group == "Control", ]
    p <- ggplot (plot, aes(x, y)) +
      geom_point(shape= 21, fill= "blue", colour= "black", size=2) +
      geom_smooth(method= "lm", se= FALSE,  colour= "red", formula=y ~ poly(x, 3, raw=TRUE)) +
      geom_errorbar(aes(ymin=y-SE, ymax=y+SE), width=.9)
    p