gpt4 book ai didi

r - 更改边框线型

转载 作者:行者123 更新时间:2023-12-02 05:54:41 26 4
gpt4 key购买 nike

我想将图表中面板边框的线型从实线更改为虚线。我尝试在主题中使用 panel.border 和 panel_border ,但 R 一直告诉我它在主题中找不到这两个函数。

最佳答案

我认为使用主题选项很难做到这一点。即使面板间距为 0,我也很确定它正在使用 element_rect 来绘制面板边框。要通过主题修改获得所需的绘图,需要修改每个面板边框的 1 或 2 条线,并了解该面是左面、右面还是中央面。

为了解决这个问题,我们可以使用 hlinevline 来代替。哈克,但它有效:

hline_df = expand.grid(visit = unique(df$visit), yint = c(-Inf, Inf))
vline_df = expand.grid(visit = unique(df$visit), xint = c(-Inf, Inf)) %>%
mutate(no_dash = !(
(xint == Inf & visit == tail(levels(visit), 1)) |
(xint == -Inf & visit == head(levels(visit), 1))
))


ggplot(df, aes(x=avisit, y=mean, group=Type, color=Type, shape=Type)) +
scale_y_continuous(breaks=seq(0,18,2), limits=c(0, 18)) +
geom_point(position=pd, cex=2) +
xlab("") +
ylab("Mean") +
scale_colour_manual(values=c("blue", "red")) +
scale_shape_manual(values=c("triangle", "circle")) +
coord_cartesian(ylim = c(0, 18)) +
facet_grid(.~factor(visit), scales = "free_x", space ="free_x",switch = "both") +
geom_hline(data = hline_df, aes(yintercept = yint)) +
geom_vline(data = vline_df, aes(xintercept = xint, linetype = no_dash), show.legend = FALSE) +
theme_bw() +
theme(axis.text.y = element_text(margin = margin(r = 0)),
panel.spacing = unit(0, "mm"),
strip.background = element_blank(),
legend.title=element_blank(),
strip.placement = "outside",
legend.background = element_rect(color="black", fill="white", size=0.5, linetype="solid"),
legend.direction = "horizontal",
panel.grid.minor = element_line(colour="white", linetype="dashed"),
panel.grid.major = element_line(colour = "white",linetype="dashed"),
panel.border = element_blank())

enter image description here

关于r - 更改边框线型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53013326/

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