如何使 1 成为 ggplot 中条形图的最高值
我正在尝试绘制从PCR得出的CT值。高CT值表明病毒水平较低,CT低表明病毒水平很高。我希望在我的数据中反映出这一点,即从40开始开始的比例,然后达到0,以便0是x轴上最高值。我知道之前已经问过一个类似的问题,但是我尝试了答案中提供的代码,发现它与我的数据集不起作用。这是我用来在GGPLOT中制作图形的代码:
ggplot(data=data, aes(x = Virus.hpi, y=ct, fill=Virus.hpi)) +
scale_fill_manual(values = c("BTV-1 0hpsi" = "blue",
"BTV-1 72hpsi" = "blue",
"BTV-8 0hpsi" = "purple",
"BTV-8 72hpsi" = "purple")) +
stat_summary(fun = mean, geom = "bar") +
stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width = 0.3) +
geom_point(data=data1, aes(x = Virus.hpi, y=ct, fill=Virus.hpi))
我在Rstudio工作。 谢谢。
I am trying to graph ct values derived from a PCR. A high ct value indicates low levels of virus and a low ct indicates high levels of virus. I would like this reflected in my data, i.e. the scale to start at 40, then go up to 0, so that 0 would be the highest value on the x axis. I know a similar question has been asked before, however I tried the code provided in the answer and found it didn't work with my data set. Here is the code I am using to make my graph in ggplot:
ggplot(data=data, aes(x = Virus.hpi, y=ct, fill=Virus.hpi)) +
scale_fill_manual(values = c("BTV-1 0hpsi" = "blue",
"BTV-1 72hpsi" = "blue",
"BTV-8 0hpsi" = "purple",
"BTV-8 72hpsi" = "purple")) +
stat_summary(fun = mean, geom = "bar") +
stat_summary(fun.data = mean_cl_normal, geom = "errorbar", width = 0.3) +
geom_point(data=data1, aes(x = Virus.hpi, y=ct, fill=Virus.hpi))
I am working in Rstudio.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ggplot2允许您逆转量表,只需在图中添加
scale__y_reverse()
:或者,您可以以相反的顺序设置y轴的限制:
请注意,请注意,这将扩展您的条形向下。
ggplot2 allows you to reverse the scales, simply add
scale_y_reverse()
to your plot:alternatively, you can set the limits of your y-axis in reverse order:
Note that this will, however, extend your bars downwards.
也许您可以用
ct
值减去 40,以获得一种“反转”的ct
值。然后反转scale_y_continuous()
中的标签。用于演示的虚拟数据
Maybe you can subtract 40 with your
ct
value, to get a kind of "reversed"ct
values. Then reverse the labelling inscale_y_continuous()
.dummy data for demonstration