【问题标题】:Wrong fill values in a ggplot2 legendggplot2 图例中的错误填充值
【发布时间】:2017-12-31 14:56:18
【问题描述】:

我在ggmap 上绘制了一个geom_point 绘图,具有单独的形状和填充样式,并且颜色保持不变。代码如下:

ggmap(m) + 
geom_point(data = d, 
           aes(x = Longitude, y = Latitude, fill = Phylum, shape = Placecount), 
               colour = 'black', size = 2) +
scale_shape_manual(values = c(21,22))

结果令人满意,除了传说中的“Phylum”自始至终错误地与黑色相关联。

【问题讨论】:

  • 从 aes() 中移除 colour='black'
  • @EdwardMendez,没有帮助。

标签: r ggplot2


【解决方案1】:

您可以使用+ guides(fill = guide_legend(override.aes = list(shape = 21))) 手动调整填充图例(或任何图例)中使用的形状值。看起来默认是 shape = 1,它不支持填充,所以你只是得到纯黑色的形状。

以下是 mtcars 的示例:

ggplot(mtcars) +
    geom_point(aes(hp, mpg, fill = as.factor(cyl), shape = as.factor(am))) +
    scale_shape_manual(values = c(21,22)) +
    guides(fill = guide_legend(override.aes = list(shape = 21)))

使用override_aes() 绘制:

情节没有:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-08
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    • 2020-01-25
    • 2014-08-07
    相关资源
    最近更新 更多