首页 > 解决方案 > ggplot2中的比例填充手册

问题描述

我正在尝试在 ggplot2 中绘制俄亥俄州的地图,并且我希望一个范围内的不同变量具有相同的颜色。我可以做 a scale_fill_continuous,但我似乎无法降低范围。理想情况下,我喜欢 0-10 绿色、11-20 蓝色、21-30 橙色等。

这是我的代码:

ggplot(oh_map, aes(x = long, y = lat)) +
  geom_polygon(aes(fill = wheat_pmt, group = group)) +
  geom_path(aes(group = group)) +
  geom_text(data = cnames, 
            aes(label = paste0("$", round(wheat_pmt, digits = 0)),
                        family="A", fontface="bold", size=4.2)) +
  scale_fill_continuous(low = "white", high = "red", na.value = "black",
                        limit=c(0,34), oob=squish)+
  labs(title = "Ohio Wheat ARC-CO Payments: Program Year 2018", 
       subtitle = "Rounded to Nearest Dollar, adusted for 85% of Base Acres and a 6.8% Government Sequestration", 
       fill = "Dollars per Acre", 
       caption = "Data Source: Author Calculation")+
  theme(axis.line=element_blank(), 
        axis.text.x=element_blank(),  
        axis.text.y=element_blank(),  
        axis.ticks=element_blank(),  
        axis.title.x=element_blank(),  
        axis.title.y=element_blank(),  
        panel.grid.major = element_blank(),  
        panel.grid.minor = element_blank(),  
        panel.border = element_blank(), 
        panel.background = element_blank(), 
        legend.position = "", 
        plot.title = element_text(hjust = 0.5,family="A",face="bold",size = 20.0),  
        plot.subtitle = element_text(hjust = 0.5,family="A",face="bold"))

标签: rggplot2

解决方案


推荐阅读