x轴堆叠条形图上的多列

时间:2017-10-06 08:04:08

标签: r plot ggplot2

我是R编程的初学者,正在探索ggplot。我试图绘制堆积条形图,以显示多个国家的3年季度收入。 我使用https://www.ibm.com/communities/analytics/watson-analytics-blog/sales-products-sample-data/

中的数据
mydata <- read.csv("~/Downloads/WA_Sales_Products_2012-14.csv") 
library(dplyr)
qtrSales <- mydata %>%
group_by(mydata$Retailer.country, mydata$Year, mydata$Quarter) %>%
summarize(Rev=sum(Revenue)) %>%

qtrSales <- data.frame(qtrSales)
colnames(qtrSales) <- c("Country", "Year", "Qtr", "Revenue")

library(ggplot2)
ggplot() + geom_bar(aes(y=qtrSales$Revenue, x = qtrSales$Year, 
fill=qtrSales$Qtr), data=qtrSales, stat="identity")

以上ggplot给了我enter image description here 我想要的是每个国家每年有3个酒吧。任何人都可以建议如何实现它?

1 个答案:

答案 0 :(得分:1)

在这里,我将 class UserCreate(CreateView): model = User fields = ['email'] success_url = '/your_success_url/' @transaction.atomic def form_valid(self, form): new_user = form.save(commit=False) # process your submitted form here. # eg. add any extra fields as: # new_user.something = something new_user.save() return super().form_valid(form) 代替Quarter放在x轴上,否则您需要使用构面。

Year

enter image description here