使用R中的Gather制作多个条形图

我有名为Category,Bottsold和County的变量。 基本上,我想使用collect和ggplot函数一次制作多个条形图。条形图将是County vs. Bottsold,但是每个图将仅考虑类别的不同值。类别具有伏特加,杜松子酒,威士忌等值。基本上,输出将是不同县与威士忌的博特索德,伏特加,伏特加,杜松子酒的图表。到目前为止,这是我尝试做的事情:

> TableA
  A B C D E
1 1 2 5 2 c
2 2 2 5 3 c
3 3 3 6 4 c
4 4 4 4 1 c
wangxiqi198706 回答:使用R中的Gather制作多个条形图

我认为这就是您所描述的。

library(tidyverse)
category <- c("Vodka","Gin","Whiskey","Vodka","Whiskey")
county <- c("1","1","2","3","3")
bott_sold <- sample(20,9)

df <- as.data.frame(cbind(category,county,bott_sold)) %>%
  mutate(bott_sold = as.numeric(as.character(bott_sold)))

ggplot(df) +
  facet_wrap(category ~ .) +
  geom_bar(aes(x = county,y = bott_sold),stat = "identity")

iowa_liquor_ggplot

本文链接:https://www.f2er.com/3077105.html

大家都在问