以下示例不起作用,但我希望對我正在嘗試做的事情有所幫助 - 更改符合條件的標簽 - EG,我想更改一個特定標簽如下:
scale_color_manual(labels = function(x) {ifelse(x == "Target", as.character("This is the target"), x)})
uj5u.com熱心網友回復:
你的方法似乎作業得很好。如果下面的代碼未捕獲您的用例,請使用最小的可重現示例更新您的問題。
library(ggplot2)
df <- data.frame(
x = c(1:2),
y = c(1:2),
col = c("Target", "Schmarget")
)
ggplot(df, aes(x, y, colour = col))
geom_point()
scale_colour_manual(
values = c("blue", "red"),
labels = function(x) {
ifelse(x == "Target", as.character("This is the target"), x)
}
)

由reprex 包于 2022-02-24 創建(v2.0.1)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/436094.html
上一篇:為什么ggsave沒有將我的繪圖保存到我的計算機上?
下一篇:我無法用給定的變數創建圖
