0

我的问题与这个线程有些相关,但我实际上希望每个符号都有黑色边框,因为我有符号重叠的实例,我认为有边框会有所帮助。但是,我有基于 geom_point 美学内部变量的颜色形状,因此使用 shape=21 和 color=NA 的解决方案并不能完全解决我的问题:我想要填充符号的颜色基于变量和基于形状在另一个变量上。这可以做到吗?或者我应该以不同的方式解决这个问题?

df <- data.frame("lon"= c(-95.350278, -95.257593, -104.987625, -104.998113),
             "lat"= c(29.752778, 29.733726, 39.751184, 39.704005),
             "type"= c("aa", "bb", "aa", "bb"),
             "mean"= c(5.369, 3.476, 7.857, 2.356))

states<-map_data("state")

mymap<- ggplot(data = states) +
geom_polygon(aes(x = long, y = lat, group = group), fill=NA, color = "black") +
coord_fixed(1.3) +
guides(fill=FALSE)+
geom_point(data=df, aes(x=lon, y=lat, color=mean, shape=type),size=5, alpha=0.8)+
scale_colour_gradient(low = "royalblue4", high = "red")+
theme_bw()+
theme(legend.position = "right",
axis.text = element_blank(),axis.line = element_blank(),
axis.ticks = element_blank(),panel.border = element_blank(),
panel.grid = element_blank(),axis.title = element_blank(),
plot.title = element_text(hjust=0.5, size=14, face="bold"))

print(mymap)

我的地图:

屏幕

感谢大家的时间和建议。

4

1 回答 1

0

您需要使用“填充”为形状着色,然后将“颜色”设置为黑色以使它们周围有一个边界。

mymap <- ggplot(data = states) +
  geom_polygon(aes(x = long, y = lat, group = group), fill = NA, color = "black") +
  coord_fixed(1.3) +
  geom_point(data = df, aes(x = lon, y = lat, fill = mean, shape = type), color = "black", size=5, stroke = 2) +
  scale_fill_gradient(low = "royalblue4", high = "red") +
  scale_shape_manual(values = c(24,21)) +
  theme_bw() +
  theme(legend.position = "right",
        axis.text = element_blank(), axis.line = element_blank(),
        axis.ticks = element_blank(), panel.border = element_blank(),
        panel.grid = element_blank(), axis.title = element_blank(),
        plot.title = element_text(hjust = 0.5, size = 14, face = "bold"))

在此处输入图像描述

于 2017-07-24T15:58:33.107 回答