我试图扩展我的 ggplot 图中的 geom_vline 线,以超出绘图空间并进入轴区域。这样做的目的是让这些线分隔轴标签,以便它可以与旁边的另一个图对齐(见下文)。
一些简短的示例代码(我有更多的行,因此需要水平线来保持直线):
library(ggplot2)
library(cowplot)
library(dplyr)
#play data set
cars.data <- mtcars %>%
mutate(car_name = rownames(mtcars)) %>%
slice(1:6)
#I would like vlines to be extend in this plot
p1 <- ggplot(cars.data, aes(x = car_name, y = hp)) +
geom_point() +
scale_x_discrete(position = "top") +
coord_flip() +
geom_vline(aes(xintercept = seq(1.5, 6.5, 1)), color = "gray60") +
xlab("")
p2 <- ggplot(cars.data, aes(y = car_name, x = 1)) +
geom_text(aes(label = disp)) +
xlab("disp") +
geom_hline(aes(yintercept = seq(1.5, 6.5, 1)), …Run Code Online (Sandbox Code Playgroud) 我遇到了 R INLA 没有计算拟合边际值的问题。我首先使用自己的数据集获得它,并且能够按照本书中的示例重现它。我怀疑一定有一些配置需要更改,或者 INLA 可能无法在后台正常工作?无论如何,这里是代码:
library("rgdal")
boston.tr <- readOGR(system.file("shapes/boston_tracts.shp",
package="spData")[1])
#create adjacency matrices
boston.adj <- poly2nb(boston.tr)
W.boston <- nb2mat(boston.adj, style = "B")
W.boston.rs <- nb2mat(boston.adj, style = "W")
boston.tr$CMEDV2 <- boston.tr$CMEDV
boston.tr$CMEDV2 [boston.tr$CMEDV2 == 50.0] <- NA
#define formula
boston.form <- log(CMEDV2) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + I(RM^2) +
AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT)
boston.tr$ID <- 1:length(boston.tr)
#run model
boston.iid <- inla(update(boston.form, . …Run Code Online (Sandbox Code Playgroud)