这是我的代码:
ggline(ToothGrowth, x = "dose", y = "len",
add = c("mean_se", "jitter"),
color = "supp", palette = "jco")
仅供参考,ToothGrowth
在此问题的底部。
我的代码不断给我这个图: 这是所有点的+/-误差,而不是我用颜色描绘的每个“补给”的误差线。我需要它来打印以下内容: 我在这里做什么错了?
感谢您的帮助。
这里是ToothGrowth
:
len supp dose
1 4.2 VC 0.5
2 11.5 VC 0.5
3 7.3 VC 0.5
4 5.8 VC 0.5
5 6.4 VC 0.5
6 10.0 VC 0.5
7 11.2 VC 0.5
8 11.2 VC 0.5
9 5.2 VC 0.5
10 7.0 VC 0.5
11 16.5 VC 1
12 16.5 VC 1
13 15.2 VC 1
14 17.3 VC 1
15 22.5 VC 1
16 17.3 VC 1
17 13.6 VC 1
18 14.5 VC 1
19 18.8 VC 1
20 15.5 VC 1
21 23.6 VC 2
22 18.5 VC 2
23 33.9 VC 2
24 25.5 VC 2
25 26.4 VC 2
26 32.5 VC 2
27 26.7 VC 2
28 21.5 VC 2
29 23.3 VC 2
30 29.5 VC 2
31 15.2 OJ 0.5
32 21.5 OJ 0.5
33 17.6 OJ 0.5
34 9.7 OJ 0.5
35 14.5 OJ 0.5
36 10.0 OJ 0.5
37 8.2 OJ 0.5
38 9.4 OJ 0.5
39 16.5 OJ 0.5
40 9.7 OJ 0.5
41 19.7 OJ 1
42 23.3 OJ 1
43 23.6 OJ 1
44 26.4 OJ 1
45 20.0 OJ 1
46 25.2 OJ 1
47 25.8 OJ 1
48 21.2 OJ 1
49 14.5 OJ 1
50 27.3 OJ 1
51 25.5 OJ 2
52 26.4 OJ 2
53 22.4 OJ 2
54 24.5 OJ 2
55 24.8 OJ 2
56 30.9 OJ 2
57 26.4 OJ 2
58 27.3 OJ 2
59 29.4 OJ 2
60 23.0 OJ 2
答案 0 :(得分:1)
我已经尝试了您的代码,似乎没有问题,也here所述。
但是,您也可以尝试使用ggplot2
软件包:
library(ggsci) # to have the blue and yellow theme
ggplot(ToothGrowth, aes( x = dose, y = len, color = supp, group = supp )) +
geom_jitter()+ # jitter it
stat_summary(fun.y = mean, # here add the summary, I suppose
fun.ymin = function(x) mean(x) - sd(x), # mean and +-sd
fun.ymax = function(x) mean(x) + sd(x),
geom = "errorbar") +
stat_summary(fun.y= function(x) mean(x), geom="line", aes(group = supp))+
stat_summary(fun.y = mean,geom = "point") +
# here you add the line
scale_color_jco()+ # here the colors
theme(panel.background = element_rect(fill = "white", colour = "black")) # you can customize
# many features with ggplot