英文:
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 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)
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()
英文:
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()
<!-- -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论