gpt4 book ai didi

r - ggplot : axis don't intersect at origin

转载 作者:行者123 更新时间:2023-12-04 11:25:21 26 4
gpt4 key购买 nike

我正在尝试使用 ggplot 绘制以下向量:

library(ggplot2)
vec =c(44.55 ,47.81 ,40.28 ,44.32 ,53.57 ,45.68 ,52.02 ,44.27 ,33.44 ,41.16)
by = c("1994-04-30", "1994-05-31", "1994-06-30", "1994-07-31", "1994-08-31", "1994-09-30", "1994-10-31", "1994-11-30", "1994-12-31", "1995-01-31")
vec.zoo = zoo(vec, order.by = as.Date(by))


g <-ggplot(vec.zoo) +
geom_line (aes(x=index(vec.zoo), y=coredata(vec.zoo)), color = "cadetblue4", size = 0.6) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
xlab("Time") +
ylab("Hit Ratio") +
scale_y_continuous(limits = c(0, 100))
scale_x_date(limits = c(start(vec.zoo), end(vec.zoo)))
g

尽管我设置了轴的限制,但它们仍然不会在原点相交。我想在 x= 0处设置交点和 y = start(vec) .

这是我得到的结果:

enter image description here

任何帮助,将不胜感激!!谢谢!!

最佳答案

您可以使用 expand您的 scale 中的论点调用。设置 expand为零,删除数据和轴之间的默认小间隙(请参阅 here )

g <-ggplot(vec.zoo) +
geom_line (aes(x=index(vec.zoo), y=coredata(vec.zoo)), color = "cadetblue4", size = 0.6) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
xlab("Time") +
ylab("Hit Ratio") +
scale_y_continuous(limits = c(0, 100), expand = c(0, 0)) +
scale_x_date(limits = c(start(vec.zoo), end(vec.zoo)), expand = c(0, 0))
g

关于r - ggplot : axis don't intersect at origin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20050062/

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