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()' –