Retrieve the value of the shaft tag in ggPlot2_3.0.0

How to extract the numbers used to mark the y-axis and x-axis in the following ggplot (20, 30, 40 and 10, 15, 20, 25, 30, 35)?

Plot

From r-statistics.co

enter image description here

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")

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 has changed slightly. 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"

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

enter image description here

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")

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"

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2734 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.