Home > Blockchain >  Why does the shape of the legend's elements are not the same than the ones on the chart with `g
Why does the shape of the legend's elements are not the same than the ones on the chart with `g

Time:01-22

library(ggplot2)

ggplot(mtcars)   
  aes(x = mpg, y = disp, size = cyl)   
  geom_point()  
  geom_smooth(level = 0.99, method = "loess")  

enter image description here As you can see there are circles in the charts, but there are rectangles in the legend.

How to have circles in the legend as well?

CodePudding user response:

You should not add aes separately, instead you can do this:

library(ggplot2)

ggplot(mtcars, aes(x = mpg, y = disp))   
  geom_point(aes(size = cyl))  
  geom_smooth(level = 0.99, method = "loess")  
#> `geom_smooth()` using formula = 'y ~ x'

  • Related