简体   繁体   English

绘制单个图中的平均值

[英]Plot average of values in single plot

I want to plot single bar in a graph so it would look like picture below 我想在图形中绘制单个条形,因此它看起来像下面的图片

在此处输入图片说明

I created test data and calculate its mean. 我创建了测试数据并计算其平均值。

value <- c(99,44,100,120,88)
value_mean <- mean(value)

And plot them using below code 并使用下面的代码绘制它们

barplot(value_mean, horiz=T, width=30, cex.names=0.5 ,ylim=c(0,200), col="red")

Buth the output is not even close. 但是,输出甚至没有关闭。

在此处输入图片说明

I've also looked at this links Single bar barchart in ggplot2, R R Barplot with one bar - how to plot correctly 我也看过此链接ggplot2中的单个条形图, 带有一个条形的 R R Barplot-如何正确绘制

So my output should be something like the first picture. 所以我的输出应该类似于第一张图片。 I was thinking that could solve ggplot. 我在想可以解决ggplot。

If everything else fails, you can draw a rectangle like this: 如果其他所有操作失败,则可以绘制一个矩形,如下所示:

par(mar = c(12, 2, 12, 2))
plot(0, type="n", ylim=c(-1, 1), xlim=c(0, 200), axes = F, bty = "n",ylab="", xlab="label")
rect(0, -.7, value_mean, .7, col="red", border=NA)
text(value_mean, 0, pos=4, label=value_mean)
axis(1, at=seq(0, 200, by=40))

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM