r - 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"))
解决方案
推荐阅读
- javascript - 如何通过使用 JS EventListener 的 HTML 表单的输入来更改 HTML 元素的背景颜色
- flutter - 将数据添加到 initState 中的列表以将其显示为 DropdownMenuItem
- c++ - 我遇到了一个错误 E0003,它说#include 文件包含它自己
- python - 不一致的返回值Pylint
- macos - 如何在 macOS 上的 SwiftUI 中实现拖放到 3rd 方应用程序
- notepad++ - 如何用逗号空格小写字符替换句号空格和小写字符?
- css - 响应性 CSS 媒体查询或容器?
- javascript - ReactJS:Okta Auth RestoreOriginalUri 函数未重定向
- python - Pyspark Py4JJava错误:
- django - 根据 django 中给出的项目数量打印循环数据