ggplot2 barplot:同时减小宽度和间距

时间:2015-09-22 14:55:51

标签: r ggplot2

我想用ggplot制作一个条形图。理想情况下,我的酒吧应该很好,它们之间不应该有空格。有什么想法我能做到吗?

data_hrs <- rnorm(n=513, m=20, sd=1) 
hours <- 528
days <- ceiling(hours/24)
days_hours <- days*24

data_hrs[days_hours] <- NA ## padding with NA to reach full no of days
hours <- length(data_hrs)
hours_count <- seq(1:24)
hours_count <- rep(hours_count,days)

day_count <- NA ## counts the days
for (t in 1:days){
  day_count[((t-1)*24+1):(t*24)] <- rep(t,24)
}

df_plot <- data.frame(day_count, hours_count, data_hrs)

print(ggplot(df_plot, aes(x=hours_count, y = data_hrs))+ 
      geom_bar(stat="identity", width = 0.1, position = position_dodge(width = 0.5))+
      theme_bw()+
      facet_grid(day_count ~ .)+
      scale_x_discrete(limits = c(seq(1:24)))+
      theme(axis.text.x = element_text(angle = 90, hjust = 1)))

这给了我以下(使用我的数据):enter image description here

1 个答案:

答案 0 :(得分:1)

使用 A1: Michael A B1: MichaelA C1: =IF(A1=B1,"Y","N") A2: Justin M. B2: Justin M C2: =IF(A2=B2,"Y","N") 删除栏之间的空格。如果你想要精细的条形,创建一个狭窄的图。宽图表与条形图之间没有空格的细条不兼容。

Cloning repository...
Cloning into '/builds/ns/project'...
fatal: Authentication failed for 'https://gitlab-ci-token:d33[...]a6@git.geekwu.org/ns/project.git/'

ERROR: Build failed with: exit code 128