rggplot2visualizationggdist

How to change the color and size of points in ggdist::stats_dots function?


I am trying to visualize a scatterplot graph using ggdist and ggplot. I was able to get the plot to work, but I am trying to changed the color and the size of the points, and currently am not able to do that. I would like all points to be one color (like "blue" or "red"), and know where to change the size of the points.

    data <- data.frame(type = c('fruit', 'root', 'fruit', 'root'),
                         food = c('apple', 'taro', 'banana', 'potato'),
                         weight = c(2, 4, 3, 2))


ggplot(data, aes(x = data[,1], y = data[,3])) +
          ggdist::stat_dots(side = "both") +
          theme_classic() +
          theme(axis.title.x = element_text(size = 20 ), axis.text.x = element_text(size = 15),
          axis.title.y = element_text(size = 20 ), axis.text.y = element_text(size = 15),
          plot.title = element_text(size = 30),
          plot.subtitle = element_text(size = 20)) +
          stat_summary(fun = mean, geom = "point", shape = 18, size = 6, color="black")  + 
          stat_summary(fun.data = give.n, geom = "text", fun = median, size = 15, position = position_dodge(width = 0.75)) +
          labs(title = "title", subtitle = "sub title"  ,x = "x title", y = "y title",
               caption = "caption") +
          scale_y_continuous(expand = c(0, 0), limits = c(0, 4.5))

Solution

  • You could use the arguments fill and dotsize to change the color and size of the dots like this:

    library(ggplot2)
    ggplot(data, aes(x = data[,1], y = data[,3])) +
      ggdist::stat_dots(side = "both", fill = "blue", dotsize = 0.2) +
      theme_classic() +
      theme(axis.title.x = element_text(size = 20 ), axis.text.x = element_text(size = 15),
            axis.title.y = element_text(size = 20 ), axis.text.y = element_text(size = 15),
            plot.title = element_text(size = 30),
            plot.subtitle = element_text(size = 20)) +
      stat_summary(fun = mean, geom = "point", shape = 18, size = 6, color="black")  + 
      #stat_summary(fun.data = give.n, geom = "text", fun = median, size = 15, position = position_dodge(width = 0.75)) +
      labs(title = "title", subtitle = "sub title"  ,x = "x title", y = "y title",
           caption = "caption") +
      scale_y_continuous(expand = c(0, 0), limits = c(0, 4.5))
    

    Created on 2024-03-18 with reprex v2.0.2