r - 酒吧和餐饮店的边界,ggplot
问题描述
我尝试在 ggplot 中绘制条形图,在 x 个国家/地区,每个物种的动物数量为 y。我做到了这一点,但是当我尝试勾勒出每个物种和条形图时,我得到了图表中每个值之间的边界。
我还尝试使用 reprex 包创建一个看起来更漂亮的问题,包括我的图表,但我的声誉太低,显然无法发布这些图片。
所以我只尝试代码:
创建数据框library(tidyverse)
country <- c( "AA", "AA", "BB", "BB", "CC", "CC", "DD", "DD", "EE", "EE")
sheep <-c(130, 146, 12, 15, 19, 0, 44, 57, 99, 123)
cattle <- c(11, 34, 221, 0, 91, 49, 33, 28, 19, 10)
pigs <- c(55, 0, 34, 48, 54, 0, 33, 59, 112, 23)
animals_wide <- data_frame(country, sheep, pigs, cattle)
“重塑”桌子从宽到长(tidyr::gather)
animals_long <- animals_wide %>%
gather(key = species, value = numbers, -country)
glimpse(animals_long)
由ggplot绘制
ggplot(animals_long, aes(country, numbers, fill = species)) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
scale_fill_manual(values=c("gray", "black", "white"))
尝试通过添加 geom_bar(..., color = "black) 为 bar 中的“物种”添加黑色轮廓
ggplot(animals_long, aes(country, numbers, fill = species)) +
geom_bar(stat = "identity", color = "black") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
scale_fill_manual(values=c("gray", "black", "white"))
解决方案
推荐阅读
- openlayers - openlayers 4.6.5 如何将他的下一个标记移动到新坐标
- java - 如何在列表中找到元素(尽可能快)
- html - IIS 强制下载文件扩展名“.rem”而不触发错误“没有为扩展名“.rem”注册构建提供程序。”
- php - 如何使用 Xpath 过滤对 XML 导出的搜索?
- selenium - 测试失败后如何中止Jenkins管道阶段
- html - HTML/CSS 浮动顶部和左侧
- python - Kivy ScreenManager 和 BoxLayout
- import - SAS:有趣的 Excel 导入差异
- ios - 限制对 Firebase 存储的访问,因此只有我的应用可以访问它
- javascript - 如何在 Google Script App 中模拟击键?