在根据地图上的变量绘制颜色和形状的点时,保持符号的黑色边框 (geom_point)
Keep black border of symbols when drawing points colored and shaped based on variables on a map (geom_point)
我的问题与 有点相关,但实际上我想 为每个符号设置 黑色边框,因为我有一些符号重叠的情况,我认为有边界会有所帮助。但是,我有 color 和 shape 基于美学内部的变量 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)
我的地图:
感谢大家的时间和建议。
您需要使用 "fill" 为形状着色,然后将 "color" 设置为黑色以在它们周围设置边框。
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"))
我的问题与
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)
我的地图:
感谢大家的时间和建议。
您需要使用 "fill" 为形状着色,然后将 "color" 设置为黑色以在它们周围设置边框。
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"))