问题
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