facet\u wrap获取列的计数
有个小问题我解决不了。在我的数据集中,我有三列(pluginUserID、type、timestamp),我想为每个pluginUserID创建一个带有facet wrap的ggplot。我的数据集看起来像这样,只是有更多的用户facet\u wrap获取列的计数,r,ggplot2,facet,facet-wrap,R,Ggplot2,Facet,Facet Wrap,有个小问题我解决不了。在我的数据集中,我有三列(pluginUserID、type、timestamp),我想为每个pluginUserID创建一个带有facet wrap的ggplot。我的数据集看起来像这样,只是有更多的用户 pluginUserID type timestamp 3 follow 2015-03-23 3 follow 2015-03-27 43 follow 2015-04-28
pluginUserID type timestamp
3 follow 2015-03-23
3 follow 2015-03-27
43 follow 2015-04-28
因此,在下一步中,我想创建一个带有刻面换行的ggplot,因此我的代码如下所示
timeline.plot <- ggplot(
timeline.follow.data,
aes(x=timeline.follow.data$timestamp, y=timeline.follow.data$type)
) + geom_bar(stat = "identity") +
facet_wrap(~timeline.follow.data$pluginUserID) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank()
)
timeline.plot当我看到您的数据集时,我会在可视化之前做一件事-计数
timeline.follow.data<- timeline.follow.data %>%
count(pluginUserID, type, timestamp)
后计数功能:
pluginUserID type timestamp n
3 follow 2015-03-23 1
3 follow 2015-03-27 2
43 follow 2015-04-28 2
timeline.plot <- ggplot(
timeline.follow.data,
aes(x=timeline.follow.data$timestamp, y=timeline.follow.data$n)
) + geom_bar(stat = "identity") +
facet_wrap(~timeline.follow.data$pluginUserID) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank()
)
等等
然后使用ggplot函数:
pluginUserID type timestamp n
3 follow 2015-03-23 1
3 follow 2015-03-27 2
43 follow 2015-04-28 2
timeline.plot <- ggplot(
timeline.follow.data,
aes(x=timeline.follow.data$timestamp, y=timeline.follow.data$n)
) + geom_bar(stat = "identity") +
facet_wrap(~timeline.follow.data$pluginUserID) +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank()
)
timeline.plot使用您的示例数据无法提供帮助,请使用dput添加真实数据集
您可以发布数据吗?