2017-04-18 94 views
2

所以这里是我在SO中的第一篇文章。 我有一个数据集,看起来如下所示。但这是为了更多的桶和更长的时间段。我正在寻找某种交互式阴谋,这将非常适合代表这些数据。代表需要考虑到所有提到的专栏,并且需要互动。我尝试通过诸如dygraphs,ggplot2,rcharts和其他一些软件包,但没有找到任何简单方便的东西。我刚刚开始与R,所以一些见解将是伟大的。代表基于R中多个分类的时间序列数据

Month Age Gender Percentage 
Mar-16 0-20 F   1.01 
Mar-16 0-20 M   0.46 
Mar-16 21-30 F   5.08 
Mar-16 21-30 M   4.03 
Apr-16 0-20 F   2.34 
Apr-16 0-20 M   3.55 
Apr-16 21-30 F   6.78 
Apr-16 21-30 M   9.08 
May-16 0-20 F   3.56 
May-16 0-20 M   3 
May-16 21-30 F   2.08 
May-16 21-30 M   10 
+1

可以ggplotly&GGPLOT2使用,并且组由年龄和性别的颜色,那么你可以绘X =月和y =百分比。 gglotlot会给你想要的交互。 ggplot2将创建好的方式来创建情节 –

回答

1

这里有一个快速可视化GGPLOT2和plotly通过@KppatelPatel 所建议的ggplotly输出将是你的图形用户界面上的互动情节,具有悬停信息例如Month: Apr-16; Percentage: 2.34; Gender: F

library(ggplot2) 
library(plotly) 

p <- ggplot(dat, aes(x=Month, y=Percentage, fill=Gender)) + 
    geom_bar(stat="identity", position = position_dodge()) + 
    facet_wrap(~Age, ncol=2) 

ggplotly(p) 

enter image description here

的data.frame dput对所提供的数据:

dat <- structure(list(Month = structure(c(2L, 2L, 2L, 2L, 1L, 1L, 1L, 
1L, 3L, 3L, 3L, 3L), .Label = c("Apr-16", "Mar-16", "May-16"), class = "factor"), 
Age = structure(c(1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 
2L, 2L), .Label = c("0-20", "21-30"), class = "factor"), 
Gender = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
2L, 1L, 2L), .Label = c("F", "M"), class = "factor"), Percentage = c(1.01, 
0.46, 5.08, 4.03, 2.34, 3.55, 6.78, 9.08, 3.56, 3, 2.08, 
10)), .Names = c("Month", "Age", "Gender", "Percentage"), class = "data.frame", row.names = c(NA, 
-12L)) 

编辑:

要绘制时间的逻辑顺序,转换本月至今格式:

library(dplyr) 
dat$Time <- dat$Month %>% 
      as.character %>% 
      paste("01-", .) %>% 
      as.Date(., format= "%d-%b-%y") 

x=Time绘制的相同ggplot上述会给你以下几点:

enter image description here

相关问题