简体   繁体   English

ggplot2图例中的填充值错误

[英]Wrong fill values in a ggplot2 legend

I have a geom_point plot over a ggmap with separate styling for shape and fill of the points and with colour kept constant. 我有一个geom_point在情节ggmap与形状之分,并用颜色填充单独的造型保持不变。 Here's the code: 这是代码:

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))

The result is satisfactory except for the legend, where 'Phylum' is wrongly associated with black throughout. 除了图例以外,结果都是令人满意的,其中“ Phylum”始终错误地与黑色相关联。

在此处输入图片说明

You can manually adjust which the shape values are used in your fill legend (or any legend) with + guides(fill = guide_legend(override.aes = list(shape = 21))) . 您可以使用+ guides(fill = guide_legend(override.aes = list(shape = 21)))手动调整在填充图例(或任何图例)中使用的形状值。 It looks like the default is shape = 1, which doesn't have support for fill, so you are just getting the solid black shapes. 看起来默认值是shape = 1,它不支持填充,因此您只能得到纯黑色形状。

Here is an example with mtcars: 这是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)))

plot with override_aes() : override_aes()绘制:

在此处输入图片说明

plot without: 情节不包括:

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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