简体   繁体   中英

How can I fix missing color scale in the legend when I plot continuous color using ggplot2?

Using Windows Server 2008 R2 Standard; R 3.5.3; Rstudio 1.1.453; ggplot2 3.2.1

When I create a plot using ggplot2 that includes a continuous variable that is displayed using color, the legend appears with the range of reference values, but the color scale to the left of the numbers in the legend does not appear (it just remains white to the left of the numbers). How do I make the continuous color scale appear in the legend? Example below and I've attached the resulting plot. The color scale is missing in Rstudio and also when I export to png using png() function.

ggplot(mtcars,
       aes(x = qsec,
           y = mpg,
           colour = wt)) +
  geom_point()

image of resulting plot, which is missing the color scale in the legend

在此处输入图像描述

mlcyo's suggestion (and code in link) fixed the problem when the plot is saved to png. Thank you!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM