我正在使用 geom_tile 制作一種熱圖,我遇到了一個關于圖例的小美學問題。照原樣,我正在使用資料中的級別數在圖例中生成中斷,并且情節看起來很棒,但是中斷的間隔不相等,并且是非整數值。
有誰知道如何撰寫中斷引數,以便圖例中的中斷是等距且整數值的?
這是我的代碼:
# Fake data
Freq <- rep(1:13, 15)
SD <- c(rep(1, 13), rep(2, 13), rep(3, 13), rep(4, 13), rep(5, 13), rep(6, 13), rep(7, 13), rep(8, 13), rep(9, 13), rep(10, 13), rep(11, 13), rep(12, 13), rep(13, 13), rep(14, 13), rep(15, 13))
Intro_0 <- sample(80:120,195,TRUE)
test2 <- cbind(Freq, SD, Intro_0)
# Setting up colours
colours <- colorRampPalette(c("deeppink4", "violetred", "palevioletred", "rosybrown1"))(165)
test2$Intro_0 <- factor(test2$Intro_0)
N <- nlevels(test2$Intro_0)
# Plotting
ggplot(test2, aes(x = Freq, y = SD, fill = Intro_0))
geom_tile()
xlab("Frequency of Disturbance")
ylab("Magnitude of Disturbance")
labs(fill="Longevity")
scale_x_discrete(labels= c("Once every 10 days", " ", " ", "Once per week", " ", "Once every 5 days", " ", " ", "Once every 2 days", "Once per day", "Twice per day", " ", "10 times per day"))
scale_fill_manual(values=colours, breaks=levels(test2$Intro_0)[seq(1, N, by=30)])
#scale_fill_manual(values=colours, breaks=c(80, 90, 100, 110, 120))
theme_tufte()
theme(axis.text.x = element_text(angle = 45, hjust=1))
我試過這個:
scale_fill_manual(values=colours, breaks=c(80, 90, 100, 110, 120))
但傳說就這樣消失了?
非常感謝您的幫助!??
uj5u.com熱心網友回復:
我懷疑問題在于您的資料不是連續的,而是可能是字串或因素
看起來問題在于您如何定義休息時間。目前還不清楚你是如何想出休息時間的?
geom_tile()
將自動使圖例基于整數。
我試圖用一些假資料重現你的問題:
y = data.frame(value = sample(c(10.5273:100.727437), 300, replace = TRUE),
group1 = sample(c("op1", "op2", "op3", "op4", "op5", "op6"),
300, replace = TRUE),
group2 = sample(c("x1", "x2", "x3", "x4", "x5", "x6", "x7"),
300, replace = TRUE))
colours <- colorRampPalette(c("deeppink4", "violetred",
"palevioletred", "rosybrown1"))(165)
ggplot(data = y, aes(x = group2, y = group1, fill = value))
geom_tile()
它給出了整數中斷
您能否使用這些虛假資料來嘗試重現中斷問題,以便我們了解發生了什么?
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/491038.html
下一篇:強制將時間軸設定在特定邊界