如何为GEOM_TILE图中的传说中指定突发点?

发布于 2025-02-07 02:33:35 字数 1587 浏览 1 评论 0原文

我正在使用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.

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

天荒地未老 2025-02-14 02:33:35

我怀疑问题是您的数据不是连续的,但可能是字符串或因素


似乎问题在于您如何定义休息时间。目前尚不清楚您是如何提出休息时间的吗?

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() 

它可以通过整数休息

您能否使用此假数据尝试通过休息来重现问题,以便我们看到发生了什么?

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:

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() 

And it gives this with integer breaks
enter image description here

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文