ggplot2 boxplots按周计算 [英] ggplot2 boxplots by week

查看:122
本文介绍了ggplot2 boxplots按周计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  df < -  data.frame(value = rnorm(62),my .date = seq(as.Date(2013-12-01),as.Date(2014-01-31),by =1 day))

library(ggplot2 )
ggplot(df,aes(as.Date(my.date),value))+ geom_boxplot()+ scale_x_date(minor_breaks =1 week,labels = date_format(%W \%%b ))


在12月1日至1月31日期间,我怎样才能制作出每周都有单个箱型图的情节?所以在一个地块内,应该有大约8个盒子。希望解决方案使用 ggplot() scale_x_date()

library(ggplot2)
ggplot(df,aes(format(as.Date(my.date), )%+ geom_boxplot()

编辑:

(df,aes(reorder(format(as.Date(my.date),%W\\\
%b),
as.Date(my.date)),
value)) +
geom_boxplot()


This code produces a single boxplot:

df <- data.frame(value = rnorm(62), my.date = seq(as.Date("2013-12-01"), as.Date("2014-01-31"), by="1 day"))

library(ggplot2)
ggplot(df, aes(as.Date(my.date), value)) + geom_boxplot() + scale_x_date(minor_breaks = "1 week", labels = date_format("%W\n%b"))

How can I produce a plot that has single boxplots for each week between 1 December and 31 January? So within the single plot, there should be about 8 boxplots. Would prefer solution that uses either ggplot() or scale_x_date().

解决方案

library(ggplot2)    
ggplot(df, aes(format(as.Date(my.date), "%W\n%b"), value)) + geom_boxplot()  

Edit:

To order the dates:

ggplot(df, aes(reorder(format(as.Date(my.date), "%W\n%b"), 
                       as.Date(my.date)), 
               value)) + 
  geom_boxplot() 

这篇关于ggplot2 boxplots按周计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆