gpt4 book ai didi

r - 如何在 ggplot 中找到 geom_line 控制点

转载 作者:行者123 更新时间:2023-12-04 17:11:18 26 4
gpt4 key购买 nike

我能够使用这个问题的答案在 ggplot 中找到 geom_curve 控制点:

How to find the geom_curve control points in ggplot

我现在想知道如何将相同的函数应用于 geom_line 以获得我在 ggplot 上创建的 geom_line 沿线的所有控制点。

b$data[[1]] 给出起点和终点

p$layers[[1]]$geom_params 给出曲线信息(角度,曲率,...)。

但我如何找到沿 geom_line 的所有坐标/点,以便我可以用这些点重现该线?

  C <- ggplot() +
geom_sf(data = world, fill = "grey69", size = 0.1, colour = "transparent") +
scale_x_continuous(limits = c(-180, 180), breaks = seq(-180, 180, by = 40)) +
scale_y_continuous(limits = c(-90, 90), breaks = seq(-90, 90, by = 30)) +
coord_sf(expand = FALSE) +
labs(x = "Longitude", y = "Latitude") +
geom_sf(data = world, color = "grey87", fill = "grey87", size = 0.1) +
geom_line(aes(c(19, 6),c(-32,-40)),
lineend = "round", size = 0.4, col = "gray20", linetype = "solid", alpha = 0.6)

最佳答案

ggplot_build 可能对您有所帮助。例如,数据a 看起来像

  weathersit     xmax         ymax
1 Bad 4715.689 0.0002230112
2 Very_Bad 4063.629 0.0002209857
3 God_Awful 2015.291 0.0002969503

然后让 b geom_line 项目为

b <- a %>%
ggplot(aes(xmax, ymax)) +
geom_line()

最后,

ggplot_build(b) %>% purrr::pluck("data",1)

x y PANEL group flipped_aes colour size linetype alpha
3 2015.291 0.0002969503 1 -1 FALSE black 0.5 1 NA
2 4063.629 0.0002209857 1 -1 FALSE black 0.5 1 NA
1 4715.689 0.0002230112 1 -1 FALSE black 0.5 1 NA

有了这个结果,您就可以重现这一行了。这种方式可用于许多其他 geom_... 事物,例如 geom_density

关于r - 如何在 ggplot 中找到 geom_line 控制点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69384466/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com