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

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

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,它提供了一个现成的选项来添加内部坐标轴:

library(ggplot2)
library(ggh4x)

iris |>
  ggplot(aes(Sepal.Length, Sepal.Width, color = Species)) +
  geom_point() +
  theme(axis.line = element_line()) +
  coord_axes_inside(
    labels_inside = TRUE,
    xintercept = 6,
    yintercept = 3
  )

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

英文:

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

library(ggplot2)
library(ggh4x)

iris |&gt;
  ggplot(aes(Sepal.Length, Sepal.Width, color = Species)) +
  geom_point() +
  theme(axis.line = element_line()) +
  coord_axes_inside(
    labels_inside = TRUE,
    xintercept = 6,
    yintercept = 3
  )

在图表中心创建新坐标轴: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:

确定