小编ske*_*tor的帖子

ggplot2:使用stat_smooth时的透明图例背景

我有两个情节.一条线条平滑:

library(splines)
library(ggplot2)

ggplot(mtcars, aes(hp, qsec)) + stat_smooth(aes(group = cyl,
       colour = factor(cyl)),
       method = "glm",
       formula = y ~ ns(x, 1),
       level = 1e-9,
       size = I(1)) +
  theme(panel.background=element_rect(fill="transparent",colour=NA),
        plot.background=element_rect(fill="transparent",colour=NA),
        legend.key = element_rect(fill = "transparent", colour = "transparent"))
Run Code Online (Sandbox Code Playgroud)

一个没有:

ggplot(mtcars, aes(hp, qsec)) +
  geom_point(aes(group = cyl, colour = factor(cyl))) +
  theme(panel.background=element_rect(fill="transparent",colour=NA),
        plot.background=element_rect(fill="transparent",colour=NA),
        legend.key = element_rect(fill = "transparent", colour = "transparent"))
Run Code Online (Sandbox Code Playgroud)

如何在第一个图中获得白色或透明的图例背景?为什么相同的主题命令在第二个绘图中完成工作?

plot r smoothing ggplot2

8
推荐指数
1
解决办法
8084
查看次数

标签 统计

ggplot2 ×1

plot ×1

r ×1

smoothing ×1