admin管理员组文章数量:1431426
My graph displays text outside of existing values range on the x axis.
In order to get the text at the correct y level, I increased x axis limits using coord_cartesian
.
I would like to remove part of the x axis, keeping the x limit of the plot.
My current reproducible code
### Loading library
library(ggplot2)
### Initiating data
data(iris)
### Initiating plot
ggplot(data=iris, aes(x=Sepal.Length, y=Species)) +
geom_point() +
coord_cartesian(xlim=c(4, 10)) +
geom_text(aes(y=Species, x=9, label=Species)) +
theme_classic()
My aim
Not sure this is feasible
My graph displays text outside of existing values range on the x axis.
In order to get the text at the correct y level, I increased x axis limits using coord_cartesian
.
I would like to remove part of the x axis, keeping the x limit of the plot.
My current reproducible code
### Loading library
library(ggplot2)
### Initiating data
data(iris)
### Initiating plot
ggplot(data=iris, aes(x=Sepal.Length, y=Species)) +
geom_point() +
coord_cartesian(xlim=c(4, 10)) +
geom_text(aes(y=Species, x=9, label=Species)) +
theme_classic()
My aim
Not sure this is feasible
Share Improve this question asked Nov 19, 2024 at 13:28 Yacine HajjiYacine Hajji 1,4891 gold badge5 silver badges23 bronze badges 2 |1 Answer
Reset to default 7ggplot(data=iris, aes(x=Sepal.Length, y=Species)) +
geom_point() +
coord_cartesian(xlim=c(4, 10)) +
geom_text(aes(y=Species, x=9, label=Species)) +
theme_classic() +
scale_x_continuous(breaks = c(4,6,8)) +
guides(x = guide_axis(cap = "upper"))
本文标签: rRemove part of x axiskeeping x axis limitsStack Overflow
版权声明:本文标题:r - Remove part of x axis, keeping x axis limits - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745558921a2663352.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
geom_text(aes(y=Species, x=9, label=Species))
overplots the labels for each row of a species, which gives them this wonky bold look. Useannotate
, or something likegeom_text(aes(y=Species, x=9, label=Species), \(d) dplyr::distinct(iris["Species"]))
– Axeman Commented Nov 19, 2024 at 19:25