我想制作一个简单的图表:中间的意思,最小和最大的胡须。无箱。最简单的方法是什么? 感谢。
structure(list(Country = structure(c(1L, 9L, 6L, 5L, 3L, 8L,
7L), .Label = c("BU", "CZ", "ES", "HU", "LT", "LV", "PL", "SL",
"UK"), class = "factor"), Mean = c(0.68, 0.56, 0.44, 0.31, 0.27,
0.8, 0.13), Min = c(0.44, 0.34, -0.35, -0.05, -0.16, 0.76, -0.44
), Max = c(0.85, 0.83, 0.83, 0.84, 0.55, 0.85, 0.84)), .Names = c("Country",
"Mean", "Min", "Max"), row.names = c(1L, 2L, 3L, 4L, 5L, 8L,
9L), class = "data.frame")
答案 0 :(得分:1)
这是使用bxp
完成任务的一种黑客方式:
bxp(
list(
stats=rbind(df$Min,df$Max,df$Mean,df$Min,df$Max),
n=seq_len(nrow(df)),
names=df$Country
),
lty=1,
boxlty=0
)
答案 1 :(得分:0)
使用ggplot执行此操作的一种方法是使用tidyr
包gather
函数以长格式重新生成数据,并按如下方式使用:
library(tidyr)
library(ggplot2)
df <- df %>% gather(Type, Value, -Country)
ggplot(df, aes(x = Country, y = Value, col = Country)) +
geom_line() +
geom_point(size = 2) +
theme(legend.position = 'none')
答案 2 :(得分:0)
感谢@astrosyam,我就是这样做的。
corr1 = corr[c(1:5, 8:9),1:4] # to remove NAs
# to order the cournties the way I need
Country1 = factor(corr1$Country, levels(corr1$Country)[c(1,9,6,5,3,8,7)])
x = c(1,2,3,4,5,6,7,8,9)
plot(Country1, corr1$Mean, pch=19, ylim=range(c(corr1$Mean-corr1$Min, corr1$Mean+corr1$Min)))
# hack: we draw arrows but with very special "arrowheads"
arrows(x, corr1$Mean-corr1$Min, x, corr1$Mean+corr1$Min, length=0.05, angle=90, code=3)