Reputation: 1503
I am facing this error. I tried the solutions discussed here and here, to no avail. Clearly, there is something I am missing, not certain what. Any help would be much appreciated.
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
Upvotes: 0
Views: 884
Reputation: 206496
The geom_linerange
only allows a range for y
as indicated by the error. So Just flip your x
and y
values, and then use coord_flip
to swap the x
and y
axes when plotting.
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()
Upvotes: 3