如何确定ggplot2中角点的x和y坐标?

Nic*_*own 4 r ggplot2

这是代码:

xbreaks <- c(100, 200, 300)
ybreaks <- c(2, 3, 4, 5)
ggplot(mtcars, aes(hp, wt)) +
  scale_x_continuous(breaks=xbreaks) +
  scale_y_continuous(breaks=ybreaks) +
  geom_point()
Run Code Online (Sandbox Code Playgroud)

这是情节:

在此输入图像描述

如何找到与左下角相对应的X和Y值(我用绿点标记)?我猜他们差不多是(40,1.40),但我可以问R确切的值吗?

thc*_*thc 6

是的你可以!试试这个:

g <- ggplot(mtcars, aes(hp, wt)) +
  scale_x_continuous(breaks=xbreaks) +
  scale_y_continuous(breaks=ybreaks) +
  geom_point()

b <- ggplot_build(g)
b$layout$panel_ranges[[1]]$x.range

[1]  37.85 349.15
Run Code Online (Sandbox Code Playgroud)