我有一个.csv
文件,其中每个项目都有3个参数。如果项目为"apple"
,则3个值是:
我不知道如何仅使用“生产”值来绘制这些苹果行
这是我的代码,但是它绘制了三个值:
library(tidyverse)
library(dplyr)
df <- read.csv("C:/Users/....data.csv",
encoding = "ASCII", header = TRUE,
sep = ","
)
ggplot(subset(df, Item == "Chillies and peppers, green"),
aes(x = Area, y = Y2014)) +
geom_bar(stat = "identity", width = 0.6) +
coord_flip()
view(df)
这是.csv link to csv
非常感谢!
您可以在调用ggplot之前过滤数据,像这样
df %>%
filter(Item == "Apples",
Element == "Production") %>%
ggplot() +
geom_bar(aes(Area, Y2014),
stat = "identity", width = 0.6) +
coord_flip()
注意:您也可以使用reorder(Area, Y2014, FUN = abs)
而不是简单的Area
。
df %>%
filter(Item == "Apples",
Element == "Production") %>%
ggplot() +
geom_bar(aes(reorder(Area, Y2014, FUN = abs),
Y2014),
stat = "identity", width = 0.6) +
coord_flip()