我想準備一個簡單的情節,其中包含一些點和帶有圖例的水平線。下面的代碼生成所需的圖和圖例,但圖例符號是形狀和線條的組合,當我想要形狀的形狀和線條的線條時。
dat <- iris %>% select(Sepal.Length)
dat$Type <- "Sepal.Length"
ggplot()
geom_point(data = dat, aes(x = as.numeric(row.names(dat)), y = Sepal.Length, colour = Type), shape = 10, size = 2)
geom_hline(aes(yintercept = 6, colour = "Some line"), linetype = "dashed")

uj5u.com熱心網友回復:
使用 scale_*_manual 分配自定義線型和形狀,如下所示:
dat %>%
ggplot()
geom_point(aes(x = as.numeric(row.names(dat)), y = Sepal.Length, shape = Type), size = 2)
geom_hline(aes(yintercept = 6, linetype = 'Some line'))
scale_linetype_manual(values = c('Some line' = 'dashed'))
scale_shape_manual(values = c('Sepal.Length' = 10))

轉載請註明出處,本文鏈接:https://www.uj5u.com/net/483758.html
上一篇:ggplot2中的Y軸位置
下一篇:除形狀外具有不同顏色的線性回歸線
