[英]How to plot table data in R
I have a table output as follows. 我有一个表输出如下。
Friday Monday Saturday Sunday Thursday Tuesday Wednesday
Card 18167 18381 20068 18721 17604 18753 17826
Cash 13541 13100 13201 13510 13231 12865 13426
Discount 587 594 578 572 602 622 583
I want to plot this on a 3 bar chart. 我想将其绘制在3条形图上。 on x axis there will be Days listed and on y axis will be a card data.
在x轴上将列出天,在y轴上将列出卡片数据。
We can use ?barplot
我们可以使用
?barplot
barplot(tbl, beside=TRUE, legend = TRUE)
Or using ggplot
或使用
ggplot
library(dplyr)
library(ggplot2)
tbl %>%
as.data.frame() %>%
ggplot(., aes(x= Var2, y = Freq)) +
geom_bar(aes(fill=Var1), position = "dodge", stat = "identity")
tbl <- structure(c(18167L, 13541L, 587L, 18381L, 13100L, 594L, 20068L,
13201L, 578L, 18721L, 13510L, 572L, 17604L, 13231L, 602L, 18753L,
12865L, 622L, 17826L, 13426L, 583L), .Dim = c(3L, 7L), .Dimnames = list(
c("Card", "Cash", "Discount"), c("Friday", "Monday", "Saturday",
"Sunday", "Thursday", "Tuesday", "Wednesday")), class = "table")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.