如何在下面的ggplot中提取用于标记y轴和x轴的数字(分别为20,30,40和10,15,20,25,30,35)? 情节 从r-statistics.co起 可重现的代码 # Scatterplottheme_set(theme_bw()) # pre-set the bw theme.g - ggplot(mpg, aes(cty, h
情节
从r-statistics.co起
可重现的代码
# Scatterplot theme_set(theme_bw()) # pre-set the bw theme. g <- ggplot(mpg, aes(cty, hwy)) g + geom_count(col="tomato3", show.legend=F) + labs(subtitle="mpg: city vs highway mileage", y="hwy", x="cty", title="Counts Plot")
我已经尝试查看str(g)的输出,但是成功了.
基于CPak的答案,ggplot2_3.0.0的结构略有变化.现在可以使用以下标签提取标签:ggplot_build(g)$layout$panel_params[[1]]$y.labels #[1] "20" "30" "40" ggplot_build(g)$layout$panel_params[[1]]$x.labels #[1] "10" "15" "20" "25" "30" "35"