任何想法为什么这个情节会在情节中产生白色条纹:
ggplot(test_l,aes(x=date,y=as.factor(IDNum),fill=as.factor(AE)))+
geom_raster(hjust=0,vjust=0)+
theme_classic()+
theme(axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
panel.grid.major.x =element_blank())+
scale_fill_grey()
虽然将as.factor添加到数据值会给出正确的输出吗?
ggplot(test_l,aes(x=as.factor(date),y=as.factor(IDNum),fill=as.factor(AE)))+
geom_raster(hjust=0,vjust=0)+
theme_classic()+
theme(axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
panel.grid.major.x =element_blank())+
scale_fill_grey()
我检查了我是否有任何缺失的日期值:
> identical((test_l %>% group_by(date) %>% summarize())$date,seq(ymd("2004-01-15"),ymd("2014-12-15"),by='1 month'))
[1] TRUE
此外,还为所有日期值分配了值:
> table(test_l$AE)
A02 P01 R01 F02 G01 X09 X11 X12 X14 X16 NADA <NA> Sum
44 116 140 29 101 57 4 83 113 150 12661 0 13498
> length(test_l$date)
[1] 13498
新编辑。最小的可重现数据:
> dput(test_l)
structure(list(IDNum = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L), .Label = c("2917529", "4431719"), class = "factor"), date = structure(c(12432,
12463, 12492, 12523, 12553, 12584, 12614, 12645, 12676, 12706,
12737, 12767, 12798, 12829, 12857, 12888, 12918, 12949, 12979,
13010, 13041, 13071, 13102, 13132, 13163, 13194, 13222, 13253,
13283, 13314, 13344, 13375, 13406, 13436, 13467, 13497, 13528,
13559, 13587, 13618, 13648, 13679, 13709, 13740, 13771, 13801,
13832, 13862, 13893, 13924, 13953, 13984, 14014, 14045, 14075,
14106, 14137, 14167, 14198, 14228, 14259, 14290, 14318, 14349,
14379, 14410, 14440, 14471, 14502, 14532, 14563, 14593, 14624,
14655, 14683, 14714, 14744, 14775, 14805, 14836, 14867, 14897,
14928, 14958, 14989, 15020, 15048, 15079, 15109, 15140, 15170,
15201, 15232, 15262, 15293, 15323, 15354, 15385, 15414, 15445,
15475, 15506, 15536, 15567, 15598, 15628, 15659, 15689, 15720,
15751, 15779, 15810, 15840, 15871, 15901, 15932, 15963, 15993,
16024, 16054, 16085, 16116, 16144, 16175, 16205, 16236, 16266,
16297, 16328, 16358, 16389, 16419, 12432, 12463, 12492, 12523,
12553, 12584, 12614, 12645, 12676, 12706, 12737, 12767, 12798,
12829, 12857, 12888, 12918, 12949, 12979, 13010, 13041, 13071,
13102, 13132, 13163, 13194, 13222, 13253, 13283, 13314, 13344,
13375, 13406, 13436, 13467, 13497, 13528, 13559, 13587, 13618,
13648, 13679, 13709, 13740, 13771, 13801, 13832, 13862, 13893,
13924, 13953, 13984, 14014, 14045, 14075, 14106, 14137, 14167,
14198, 14228, 14259, 14290, 14318, 14349, 14379, 14410, 14440,
14471, 14502, 14532, 14563, 14593, 14624, 14655, 14683, 14714,
14744, 14775, 14805, 14836, 14867, 14897, 14928, 14958, 14989,
15020, 15048, 15079, 15109, 15140, 15170, 15201, 15232, 15262,
15293, 15323, 15354, 15385, 15414, 15445, 15475, 15506, 15536,
15567, 15598, 15628, 15659, 15689, 15720, 15751, 15779, 15810,
15840, 15871, 15901, 15932, 15963, 15993, 16024, 16054, 16085,
16116, 16144, 16175, 16205, 16236, 16266, 16297, 16328, 16358,
16389, 16419), class = "Date"), AE = structure(c(11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L,
11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 11L, 1L, 11L, 4L, 11L,
4L, 11L, 11L, 4L, 5L, 11L, 11L, 6L, 6L, 6L, 7L, 11L, 11L, 4L,
11L, 5L, 11L, 7L, 11L, 11L, 11L, 11L, 4L, 11L, 11L, 1L, 11L,
11L, 1L, 11L, 1L, 11L, 11L, 1L, 11L, 11L, 11L, 1L, 11L, 11L,
11L, 1L, 11L, 11L, 11L, 8L, 3L, 10L, 8L, 8L, 11L, 9L, 8L, 11L,
11L, 8L, 1L, 8L, 11L, 11L, 8L, 8L, 2L, 8L, 8L, 8L), .Label = c("AF01",
"AF01, AX12", "AF01, AX16", "AF02", "AF02, AX09", "AX09", "AX09, AF02",
"AX12", "AX12, AF01", "AX16", "NADA"), class = "factor")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -264L), .Names = c("IDNum",
"date", "AE"))
答案 0 :(得分:1)
模拟使用因子对x轴的影响:
在我的数据集中,2013年没有数据:
df = data.frame(year=c(2010,2011,2012,2014,2015),value=c(10,11,12,14,15))
使用因子(),R不包括2013
ggplot(df,aes(factor(year),value))+geom_bar(stat="identity")+theme_classic()+
theme(axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
panel.grid.major.x =element_blank())+
scale_fill_grey()
如果没有因子(),R将2013年添加到x轴:
ggplot(df,aes((year),value))+geom_bar(stat="identity")+theme_classic()+
theme(axis.title.y=element_blank(),
axis.text.y=element_blank(),
axis.ticks.y=element_blank(),
panel.grid.major.x =element_blank())+
scale_fill_grey()
你最终在你的情节中留空了空间