r - ggplot图例键颜色和透明度

标签 r ggplot2 transparency legend aesthetics

我正在绘制多条线,它们是透明的。但是,我不希望图例颜色具有任何透明度。我尝试了 override.aes 但没有成功。
这类似于 question ,但本质上相反。

目前我有这个

# plot all the lines
plt <- ggplot(dt_plot,aes(x = x, y = mean_change, color = model)) +
        geom_line(aes(group = interaction(model, boot)), alpha = 0.3) +
        xlab('houses/acre') + 
        ylab('change in % prevalance') +
        scale_colour_manual(values=cbbPalette) + 
        theme_few()  + 
        theme(text=element_text(size=10),legend.title = element_blank()) + 
        guides(fill = guide_legend(override.aes= list(alpha = 1)))

transparent lines and transparent legend colors

干杯

最佳答案

除了一个小问题外,您的方法非常好:您需要

guides(color = guide_legend(override.aes = list(alpha = 1)))

相反,因为 geom_line 没有 fill 美学。

关于r - ggplot图例键颜色和透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54580202/

相关文章:

css - 来自十六进制 RGB 值的 CSS 中的半透明背景颜色

graphics - 使用SVG进行附加颜色混合(附加混合)

r - RHadoop 中的 hdfs.init() 错误

r - 如何从 Shiny 的 ggplotly 中获取数据行

r - 如何 : Automatically set fixed coordinate ratio (coord_fixed) when x- and y-axis are on different scales?

jQuery 背景 Canvas 透明度

r - 在 R 或 Excel 中计算多行中不同定性值的数量

r - 对 RStudio 中的 'Tool(s) not installed or not in PATH: ghostcript' 警告进行故障排除

r - 是否可以在 R/RStudio 中注释掉一行的一部分?

r - 处理用 ggplot2 绘制的等值线图中的异常值