0
我有一些数据,我正在索引图形。其中一个值只有NAs。所以它不会显示在图上,但条目仍然存在于图例中。我怎样才能从图例中删除它?ggplot2:删除其中一个图例条目
df <- structure(list(yrmonth = structure(c(1483228800, 1483228800,
1483228800, 1485907200, 1485907200, 1485907200, 1488326400, 1488326400,
1488326400, 1491004800, 1491004800, 1491004800), class = c("POSIXct",
"POSIXt"), tzone = "UTC"), index = structure(c(1L, 3L, 5L, 1L,
3L, 5L, 1L, 3L, 5L, 1L, 3L, 5L), .Label = c("N-S", "N-S", "E-W",
"E-W", "OS"), class = "factor"), value = c(129, 141, NA, 150.5,
209, NA, 247.5, 243, NA, 223, 226.5, NA)), .Names = c("yrmonth",
"index", "value"), row.names = 31:42, class = "data.frame")
ggplot(df, aes(x=yrmonth,y=value,colour=index)) +
geom_line()
为什么不在绘图之前删除任何“NA”? 'df [!is.na(df $ value),]' –
这个例子有些问题,你不能有两个具有相同标签的因子级别 – C8H10N4O2
'ggplot(na.omit(df),aes(x = yrmonth ,y = value,color = index))+ geom_line()' –