英文:
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).
答案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
)
<!-- -->
英文:
One option would be ggh4x::coord_axes_inside
which offers an out-of-box option to add inside axes:
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
)
<!-- -->
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论