如何调整`stat_summary_2d`图例中的间隔。

huangapple go评论89阅读模式
英文:

How to adjust the breaks of legends in stat_summary_2d

问题

stat_summary_2d中调整图例的断点是可能的吗?你已经尝试过通过在stat_summary_2d中添加breaks参数来调整断点,但图例的刻度与你的设置不同。是否可以在不使用其他额外函数的情况下调整断点?

英文:

How to adjust the breaks of legends in stat_summary_2d?

templ = data.frame(count = c(200,225,610,233,250,210,290,255,279,250),
                   temperature = c(12.2,11.6,12,8.5,4,8.2,9.2,10.6,10.8,10.9),
                   relative_humidity_percent = c(74,78,72,65,77,84,83,74,73,75))

heatf_65 = templ%>% 
  ggplot(aes(temperature, relative_humidity_percent, z =count*1.05)) +
  stat_summary_2d() +
  #geom_point(shape = 1, col = 'white') +
  scale_fill_viridis_c(breaks = c(seq(180,650,100)))+ 
  xlab('Daily Mean Temperature (°C)') +
  ylab('Daily Mean Relative Humidity Percent (%)') +
  ggtitle('Admission rate (per 100000 population)') +
  theme_classic() +
  ggeasy::easy_center_title() 
#scale_fill_binned_sequential(palette = "Terrain", rev = FALSE) 

The outcome:
如何调整`stat_summary_2d`图例中的间隔。

The scale of legend is not the same as my setting. I have already tried

heatf_65 = templ%>% 
  ggplot(aes(temperature, relative_humidity_percent, z =count*1.05)) +
  stat_summary_2d(breaks = c(seq(180,650,100))) +
  #geom_point(shape = 1, col = 'white') +
  scale_fill_viridis_c()+ 
  xlab('Daily Mean Temperature (°C)') +
  ylab('Daily Mean Relative Humidity Percent (%)') +
  ggtitle('Admission rate (per 100000 population)') +
  theme_classic() +
  ggeasy::easy_center_title() 
#scale_fill_binned_sequential(palette = "Terrain", rev = FALSE) 

The outcome is:
如何调整`stat_summary_2d`图例中的间隔。

Is it possible to adjust the breaks without using other extra function?

答案1

得分: 1

问题在于,只有符合limits范围的间断点才会显示在图例中。因此,要显示间断点的最低值,您还必须相应地设置下限:

library(ggplot2)

templ |> 
  ggplot(aes(temperature, relative_humidity_percent, z = count * 1.05)) +
  stat_summary_2d() +
  scale_fill_viridis_c(breaks = seq(180, 650, 100), limits = c(180, NA)) +
  xlab("每日平均温度 (°C)") +
  ylab("每日平均相对湿度百分比 (%)") +
  ggtitle("入院率 (每10万人口)") +
  theme_classic() +
  ggeasy::easy_center_title()

如何调整`stat_summary_2d`图例中的间隔。

英文:

The issue is that only the breaks which fit inside the limits will be shown in the legend. Hence, to show the lowest value of your breaks you also have to set the lower limit accordingly:

library(ggplot2)

templ |> 
  ggplot(aes(temperature, relative_humidity_percent, z = count * 1.05)) +
  stat_summary_2d() +
  scale_fill_viridis_c(breaks = seq(180, 650, 100), limits = c(180, NA)) +
  xlab("Daily Mean Temperature (°C)") +
  ylab("Daily Mean Relative Humidity Percent (%)") +
  ggtitle("Admission rate (per 100000 population)") +
  theme_classic() +
  ggeasy::easy_center_title()

如何调整`stat_summary_2d`图例中的间隔。<!-- -->

huangapple
  • 本文由 发表于 2023年3月1日 15:35:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75600717.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定