我的问题与this thread有些相关,但我想实际 每个符号的黑色边框,因为我有符号重叠的实例,我认为有边框会有帮助。但是,基于geom_point中美学内部的变量,我有 color 和 shape ,因此使用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)
我的地图:
感谢大家的时间和建议。
答案 0 :(得分: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"))