Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.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
R 4组中1个测量变量的线性回归图,其中1组为参考组_R_Ggplot2_Grouping_Linear Regression - Fatal编程技术网

R 4组中1个测量变量的线性回归图,其中1组为参考组

R 4组中1个测量变量的线性回归图,其中1组为参考组,r,ggplot2,grouping,linear-regression,R,Ggplot2,Grouping,Linear Regression,因此,我在4组中多次测量了1个变量,其中1组是参考组,我想与其他3组做一个回归图。你是如何生成的?我看到很多两个变量的例子都是分组绘制的,但不是我的意思(比如:) 这是我的df: df <- data.frame("Variabel" = c(1,2,3,5,6,6,3,5,8,7,4,1,3,6,8,5), "group" = c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4)) df找到了它: 我将d

因此,我在4组中多次测量了1个变量,其中1组是参考组,我想与其他3组做一个回归图。你是如何生成的?我看到很多两个变量的例子都是分组绘制的,但不是我的意思(比如:)

这是我的df:

df <- data.frame("Variabel" = c(1,2,3,5,6,6,3,5,8,7,4,1,3,6,8,5),
             "group" = c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4))
df找到了它:

我将dataframe更改为4列,因此1列=1方法及其变量

而不是为每个方法创建一行

  LM_plot <- ggplot(testfas1, aes(x=ref method))+
  geom_point(aes(y=method 2, colour="2"), size=4,alpha=1)+
  geom_smooth(aes(y=method 2, colour="2"), method="lm",alpha=0.3,fill="black", formula = my.formula) +
  geom_point(aes(y=method 3, colour="4"), size=4 ,alpha=1)+
  geom_smooth(aes(y=method 3, colour="4"), method="lm",alpha=0.3,fill="#ff0166", formula = my.formula) +
  geom_point(aes(y=method 4, colour="6"),size=4,alpha=1)+
  geom_smooth(aes(y=method 4 colour="6"), method="lm",alpha=0.3,fill="#117f80", formula = my.formula) +
  scale_y_continuous("methods 2/3/4") +
  scale_x_continuous("refernce method 1") +
  scale_colour_manual(name="legend", values=c("black", "#ff0166", "#117f80"),
                      guide = guide_legend(override.aes = list(alpha=0, size=1)))


LM_plot + theme_prism() 

LM_-plot我见过这个解决方案:使用ggplot+geom_-jitter…+geom_-jitter…+geom_-jitter…。但是肯定有一种更优雅的方法正确吗?不过有一件事……我尝试在geom_平滑中放弃alpha填充(95%的置信区间)通过图例中的override.aes…但是现在该点也消失了…只出现了几行…有什么线索可以解决这个问题吗?………我想用LM_plot+theme_prism()添加单独的公式s。如开头所示。。。。
  LM_plot <- ggplot(testfas1, aes(x=ref method))+
  geom_point(aes(y=method 2, colour="2"), size=4,alpha=1)+
  geom_smooth(aes(y=method 2, colour="2"), method="lm",alpha=0.3,fill="black", formula = my.formula) +
  geom_point(aes(y=method 3, colour="4"), size=4 ,alpha=1)+
  geom_smooth(aes(y=method 3, colour="4"), method="lm",alpha=0.3,fill="#ff0166", formula = my.formula) +
  geom_point(aes(y=method 4, colour="6"),size=4,alpha=1)+
  geom_smooth(aes(y=method 4 colour="6"), method="lm",alpha=0.3,fill="#117f80", formula = my.formula) +
  scale_y_continuous("methods 2/3/4") +
  scale_x_continuous("refernce method 1") +
  scale_colour_manual(name="legend", values=c("black", "#ff0166", "#117f80"),
                      guide = guide_legend(override.aes = list(alpha=0, size=1)))


LM_plot + theme_prism()