如何为GEOM_TILE图中的传说中指定突发点?
我正在使用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))
但是传说消失了吗?
非常感谢您的任何帮助!
I'm making a sort-of heat map using geom_tile, and I'm running into a small aesthetic issue with the legend. As is, I'm generating breaks in the legend using the number of levels in my data, and the plot looks great, but the breaks aren't equally spaced, and are non-integer valued.
Does anyone know how to write the breaks argument such that breaks in the legend are equally spaced and integer valued?
Here's my code:
# 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))
I've tried this:
scale_fill_manual(values=colours, breaks=c(80, 90, 100, 110, 120))
But the legend just disappeared?
Thanks so much for any help! ????
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我怀疑问题是您的数据不是连续的,但可能是字符串或因素,
似乎问题在于您如何定义休息时间。目前尚不清楚您是如何提出休息时间的吗?
geom_tile()
将自动使基于传奇的整数。我试图通过一些虚假数据来重现您的问题:
它可以通过整数休息

您能否使用此假数据尝试通过休息来重现问题,以便我们看到发生了什么?
I suspect the problem is that your data are not continuous but are likely strings or factors
It looks like the problem is with how you're defining your breaks. It's not really clear how you're coming up with the breaks?
geom_tile()
will automatically make the legend integer-based.I tried to reproduce your problem with some fake data:
And it gives this with integer breaks

Could you use this fake data to try and reproduce the problem with the breaks so we can see what's going on?