如何调整stat_summary_2d中图例的中断

a9wyjsp7  于 2023-03-05  发布在  其他
关注(0)|答案(1)|浏览(174)

如何调整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)

结果:

传说的比例和我的设定不一样,我已经试过了

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)

结果是:

是否可以在不使用其他额外功能的情况下调整断点?

k5ifujac

k5ifujac1#

问题是图例中只显示符合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("Daily Mean Temperature (°C)") +
  ylab("Daily Mean Relative Humidity Percent (%)") +
  ggtitle("Admission rate (per 100000 population)") +
  theme_classic() +
  ggeasy::easy_center_title()

相关问题