在图表中心创建新坐标轴:ggplot

huangapple go评论90阅读模式
英文:

Create new axis at the center of the graph: ggplot

问题

我想为现有的图表创建一个新的坐标轴。我可以使用geom_line层来实现这一点,但如何添加X轴和Y轴的标签(类似于默认的坐标轴)。

英文:

I want to create a new axis for an existing plot. I can use the geom_line layer for this but how do I add labels for X and Y axis (similar to the default axis).

在图表中心创建新坐标轴:ggplot

答案1

得分: 2

一种选择是 ggh4x::coord_axes_inside,它提供了一个现成的选项来添加内部坐标轴:

  1. library(ggplot2)
  2. library(ggh4x)
  3. iris |>
  4. ggplot(aes(Sepal.Length, Sepal.Width, color = Species)) +
  5. geom_point() +
  6. theme(axis.line = element_line()) +
  7. coord_axes_inside(
  8. labels_inside = TRUE,
  9. xintercept = 6,
  10. yintercept = 3
  11. )

在图表中心创建新坐标轴:ggplot<!-- -->

英文:

One option would be ggh4x::coord_axes_inside which offers an out-of-box option to add inside axes:

  1. library(ggplot2)
  2. library(ggh4x)
  3. iris |&gt;
  4. ggplot(aes(Sepal.Length, Sepal.Width, color = Species)) +
  5. geom_point() +
  6. theme(axis.line = element_line()) +
  7. coord_axes_inside(
  8. labels_inside = TRUE,
  9. xintercept = 6,
  10. yintercept = 3
  11. )

在图表中心创建新坐标轴:ggplot<!-- -->

huangapple
  • 本文由 发表于 2023年3月9日 23:16:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75686576.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定