使用R阴影图形的部分 [英] Shading sections of a graph using R
本文介绍了使用R阴影图形的部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
时间平均测试n se
1 20 5.80000 Exp 9 0.120
2 40 6.10000实验9 0.145
3 60 6.40000实验9 0.188
4 80 6.70000实验9 0.990
5 100 7.00000实验9 0.440
6 120 7.70000实验9 0.320
7 20 8.47000管制9 0.500
8 40 9.31700管制9 0.880
9 60 10.24870管制9 0.900
10 80 11.27357管制9 0.330
11 100 12.40093管制9 0.456
我用下面的代码来绘制它:
ggplot(data,aes(x = Time,y = Average,color = Test))+
geom_errorbar(aes(ymin = Average-se,ymax = Average + se),宽度= 0.2)+
geom_line()+
geom_point()
I想要在此图表中遮蔽特定部分。例如,我想遮蔽20至30秒的部分。这是可能的在 ggplot2
?
解决方案
这并不完全清楚你的想法。如何:?
pre $ g $ p $ ggplot(data,aes(x = Time,y = Average,color = Test))+
geom_rect(aes(xmin = 20,xmax = 30,ymin = -Inf,ymax = Inf),fill =pink,color = NA,alpha = 0.05)+
geom_errorbar(aes(ymin = Average-se,ymax = Average + se),width = 0.2)+
geom_line()+
geom_point()
So I have this data
Time Average Test n se
1 20 5.80000 Exp 9 0.120
2 40 6.10000 Exp 9 0.145
3 60 6.40000 Exp 9 0.188
4 80 6.70000 Exp 9 0.990
5 100 7.00000 Exp 9 0.440
6 120 7.70000 Exp 9 0.320
7 20 8.47000 Control 9 0.500
8 40 9.31700 Control 9 0.880
9 60 10.24870 Control 9 0.900
10 80 11.27357 Control 9 0.330
11 100 12.40093 Control 9 0.456
And I used the following code to plot it
ggplot(data, aes(x=Time, y=Average, colour=Test)) +
geom_errorbar(aes(ymin=Average-se, ymax=Average+se), width=0.2) +
geom_line() +
geom_point()
I want to shade particular sections in this graph. For example I want to shade the portion from 20 to 30 s. Is this possible to do in ggplot2
?
解决方案
From the description, it's not exactly clear what you had in mind. How about this: ?
ggplot(data, aes(x=Time, y=Average, colour=Test)) +
geom_rect(aes(xmin=20,xmax=30,ymin=-Inf,ymax=Inf),fill="pink",colour=NA,alpha=0.05) +
geom_errorbar(aes(ymin=Average-se, ymax=Average+se), width=0.2) +
geom_line() +
geom_point()
这篇关于使用R阴影图形的部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文