shift only the position of x-points when y-axis is categorical in ggplot2

172 views
Skip to first unread message

Elias Tsolis (Estatistics)

unread,
Dec 23, 2023, 8:21:01 AM12/23/23
to ggplot2
shift only the position of x-points when y-axis is  categorical in ggplot2

note that mpg/12 is intentionally there. If you remove it, points of x = mpg, and points of  x = mpg (2nd) will merge one above the other.
I would like to shift points of the 2nd mpg in y-axis.
However, y-axis is categorical.
How i can do this?

ggplot(data = mtcars, aes(x = mpg, y = reorder(cyl, -mpg), color = cyl)) +
  geom_point() +   scale_color_gradient(low = "lightgreen", high = "darkgreen")    + new_scale_colour()+
  geom_point(aes(x = mpg/12, y = reorder(cyl, -mpg), color = cyl) ) +
  scale_color_gradient(low = "lightblue", high = "darkblue")


 
Reply all
Reply to author
Forward
0 new messages