How to change the shape of dot in geom_dotplot in R?

佐手、 提交于 2021-01-28 06:41:19

问题


when working on ggplot()+geom_dotplot(), I wonder how to change the filled dot to the filled square


回答1:


Welcome to stackoverflow. This is a total hack, but it will do what you want

# plot just the dotplot
p <-
  ggplot(mtcars, aes(x = mpg)) + 
  geom_dotplot(binwidth = 1.5, dotsize = 1) +
  ylim(-0.1, 1.1)


# this is the "instructions" of the plot
gpb <- ggplot_build(p)


# gpb$data is a list, you need to use the first element
gpb$data[[1]] %>% 
  ggplot(aes(x, stackpos/max(stackpos))) +
  geom_point(shape = 22, size = 14, fill = "blue") +
  ylim(-0.1, 1.1)



来源:https://stackoverflow.com/questions/56468505/how-to-change-the-shape-of-dot-in-geom-dotplot-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!