我無法使用此數據更改此圖形中的圖例標題。ggplot2:無法更改圖例的標題
df <- structure(list(year = structure(c(1L, 1L, 2L, 2L, 2L, 3L, 3L,
3L), .Label = c("2015", "2016", "2017"), class = "factor"), Category2 = c("grower",
"starter", "grower", "layer", "starter", "grower", "layer", "starter"
), per_pound = c(0.2072, 0.382, 0.172, 0.173, 0.3705, 0.178667,
0.1736, 0.277375)), .Names = c("year", "Category2", "per_pound"
), row.names = c(NA, -8L), vars = "year", drop = TRUE, class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
而且我創建的圖表......
library (ggplot2)
p <- ggplot (data=df, aes(x=year, y=per_pound, group=Category2, color=Category2)) + geom_line() + geom_point()
p <- p + scale_fill_discrete(name="TEST")
p
這是產生此...
傳奇的名字應該是 'TEST' 而不是「類別2' 。數據框中的數據一定有問題,但我還沒有找到罪魁禍首。
-cherrytree
'P + scale_color_discrete(名稱= 「TEST」)圖例標題' – www
在'ggplot2'顏色經由'color'和分配給線填充區域通過'fill' – Mako212