[英]Using geom_errorbar in ggplot2 results in “Error: geom_errorbar requires the following missing aesthetics: ymin, ymax”
[英]How to solve: geom_linerange requires the following missing aesthetics: x, ymin, ymax
我正面临这个错误。 我尝试了此处和此处讨论的解决方案,但无济于事。 显然,我缺少一些东西,不确定是什么。 任何帮助将非常感激。
dt3<-structure(list(employee_name = structure(c(1L, 2L, 3L, 1L, 2L,
3L), .Label = c("A", "B", "C"), class = "factor"), min_salary = c(10L,
11L, 15L, 15L, 11L, 10L), mean_salary = c(15L, 16L, 16L, 16L,
16L, 15L), max_salary = c(20L, 21L, 17L, 17L, 21L, 20L), category_boss = structure(c(1L,
1L, 1L, 2L, 2L, 2L), .Label = c("Junior", "Senior"), class = "factor")), class = "data.frame", row.names = c(NA,
-6L))
ggplot(dt3) + geom_point(aes(x=mean_salary,y=employee_name,colour=category_boss),position = position_dodge(-.5)) +
geom_linerange(aes(xmin=min_salary,xmax=max_salary,y=employee_name,colour=category_boss),
position = position_dodge(-.5))
Warning: Ignoring unknown aesthetics: y, xmin, xmax
Error: geom_linerange requires the following missing aesthetics: x, ymin, ymax
geom_linerange
仅允许y
的范围,如错误所示。 所以只需翻转你的x
和y
值,然后在绘图时使用coord_flip
交换x
和y
轴。
ggplot(dt3) +
geom_point(aes(y=mean_salary, x=employee_name, colour=category_boss),
position = position_dodge(-.5)) +
geom_linerange(aes(ymin=min_salary, ymax=max_salary, x=employee_name, colour=category_boss),
position = position_dodge(-.5)) +
coord_flip()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.