Plot
From r-statistics.co
Reproducible code
# 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") pre>I have tried to view the output of str(g), but it succeeded.
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"
How to extract y-axis and x-axis in the following ggplot The numbers (20, 30, 40 and 10, 15, 20, 25, 30, 35 respectively)?
Plot
From r-statistics.co
Reproducible code
# 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") pre>I have tried to view the output of str(g), but it succeeded.
Based on CPak's answer, the structure of ggplot2_3.0.0 is slightly different Changes. Now you can use the following tags to extract tags:
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"