gpt4 book ai didi

r - ggplot2 - 如何限制面板和轴?

转载 作者:行者123 更新时间:2023-12-02 00:49:55 28 4
gpt4 key购买 nike

我想知道这个剧情怎么转:

plot 1

进入这个情节:

plot 2

如您所见,第二个图上的面板和轴仅限于数据范围。我使用设计软件制作了第二张图,但想知道代码。

我已经使用限制了 x 和 y 轴

xlim 和ylim 但没有区别。

请看下面我的代码,抱歉太乱了,第一次使用 r studio。谢谢!

ggplot() +
geom_errorbar(data = U1483_Coiling_B_M_Removed_R, mapping = aes(x = `Age (Ma) Linear Age Model`, ymin = `Lower interval*100`, ymax = `Upper interval*100`), width = 0.025, colour = 'grey') +
geom_line(data = U1483_Coiling_B_M_Removed_R, aes(x = `Age (Ma) Linear Age Model`, y = `Percent Dextral`)) +
geom_point(data = U1483_Coiling_B_M_Removed_R, aes(x = `Age (Ma) Linear Age Model`, y = `Percent Dextral`), colour = 'red') +
geom_point(data = U1483_Coiling_B_M_Removed_R, aes(x = `Age (Ma) Linear Age Model`, y = `Lab?`)) +
theme(axis.text.x=element_text(angle=90, size=10, vjust=0.5)) +
theme(axis.text.y=element_text(angle=90, size=10, vjust=0.5)) +
theme_classic() +
theme(panel.background = element_rect(colour = 'black', size = 1)) +
xlim(0, 2.85) +
ylim(0, 100)

最佳答案

您可以在指定轴比例时使用expand,如下所示:

# Load library
library(ggplot2)

# Set RNG
set.seed(0)

# Create dummy data
df <- data.frame(x = seq(0, 3, by = 0.1))
df$y <- 100 - abs(rnorm(nrow(df), 0, 10))

# Plot results
# Original
ggplot(df, aes(x, y)) +
geom_line() +
geom_point(colour = "#FF3300", size = 5)

# With expand
ggplot(df, aes(x, y)) +
geom_line() +
geom_point(colour = "#FF3300", size = 5) +
scale_y_continuous(expand = c(0, 0))

关于r - ggplot2 - 如何限制面板和轴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58641043/

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