ggplot change of size and color

I have a dataset for which I need to make a graph.

##Data
x <- c(10, 7.5, 5.5, 2.3, 3, 3.9, -2.5, -5, -9)
y <- c(3, 1.25, .75, -1.27, -.6, .88, -7.5, -5, -4)
z <- c("Good", "Good", "Good", "Average", "Average", "Average", "Bad", "Bad", "Bad")

##Dataframe
md <- data. Frame(x, y, z)

##Plotting
plot <- print(md %>% 
                ggplot(aes(x = x,
                           y = y))+
                geom_point(aes(shape = z))+
                geom_smooth(method = lm, se = F, color = "black")+
                labs(x = "X", y = "Y")+
                theme_minimal()+
                scale_shape_manual(values = c(24, 21, 25),
                                   breaks = c("Good", "Average", "Bad"))+
         
                theme(text = element_text(family = "Segoe UI"),
                      axis.line = element_line(size = .3, colour = "black", linetype = 1),
                      axis.ticks = element_line(size = .3, color="black"),
                      axis.ticks.length = unit(.1, "cm")))

Notice that as I use the scale_shape_manual I set three shapes that are analogous to the report I am preparing, hence changing them is not possible. However, what I need is:

  1. fill those shapes with black color, and
  2. increase the size of these shapes (same size for all but bigger)

I tried with scale_color_manual(values = c("#000000", "#000000", "#000000")) but it did not yield the result.

Please help me by correcting the issue.
Thank you for your time!

>Solution :

You need to add the fill = "black" and size = 3 arguments in the geom_point() outside of the aes() parameter.

Also, if you want to print a plot you don’t have to assign it to a value then print it. You can just call it

library(dplyr)
library(ggplot2)

##Data
x <- c(10, 7.5, 5.5, 2.3, 3, 3.9, -2.5, -5, -9)
y <- c(3, 1.25, .75, -1.27, -.6, .88, -7.5, -5, -4)
z <- c("Good", "Good", "Good", "Average", "Average", "Average", "Bad", "Bad", "Bad")

##Dataframe
md <- data.frame(x, y, z)

##Plotting
md %>% 
  ggplot(aes(x = x, y = y)) +
  geom_point(aes(shape = z), fill = "black", size = 3)+
  geom_smooth(method = lm, se = F, color = "black")+
  labs(x = "X", y = "Y")+
  theme_minimal()+
  scale_shape_manual(values = c(24, 21, 25),
                     breaks = c("Good", "Average", "Bad"))+
  theme(text = element_text(family = "Segoe UI"),
        axis.line = element_line(size = .3, colour = "black", linetype = 1),
        axis.ticks = element_line(size = .3, color="black"),
        axis.ticks.length = unit(.1, "cm"))

enter image description here

Leave a Reply