[英]Generate histogram from boxplots in R
I have this dataframe :我有这个数据框:
> my_data
Dimensions Mean SE Lower Upper
1 Cognitive 2.617 0.148 2.318 2.916
2 Affective 2.417 0.128 2.157 2.676
3 Comportementale 2.017 0.139 1.736 2.297
I would like to generate an histogram plot with (x=Dimensions, y=Mean and with upper and lower limits the "Lower" value and the "Upper" value).我想生成一个直方图(x=Dimensions,y=Mean,上限和下限为“Lower”值和“Upper”值)。 For the moment, I only have a "point graph" , but I would like to set up 3 bars with the peak of the bar as the point value.目前,我只有一个“点图”,但我想设置 3 个条形图,以条形图的峰值为点值。
I used ggplot2,我用了ggplot2,
ggplot(my_data,aes(x=Dimensions, y=Mean)) + geom_point() + ylim(0,4) + geom_errorbar(aes(ymin=Lower-SE, ymax=Upper+SE),width=.2)
Is this what you're looking for?这是你要找的吗?
library(ggplot2)
my_data <- tibble::tribble(
~Dimensions, ~Mean, ~SE, ~Lower, ~Upper,
"Cognitive", 2.617, 0.148, 2.318, 2.916,
"Affective", 2.417, 0.128, 2.157, 2.676,
"Comportementale", 2.017, 0.139, 1.736, 2.297)
my_data$Dimensions <- factor(my_data$Dimensions,
levels=c("Cognitive", "Affective", "Comportementale"))
ggplot(my_data, aes(x=Dimensions, y=Mean, ymin=Lower, ymax=Upper)) +
geom_bar(stat="identity", fill="gray75") +
geom_errorbar(width=.15) +
theme_classic()
Created on 2022-07-07 by the reprex package (v2.0.1)由reprex 包于 2022-07-07 创建 (v2.0.1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.