我正在研究波士頓數據集,並試圖查看每個圖表上8個房間數據的位置。我已經評論了給我錯誤的那條線。如何將vline添加到facet_grid中的所有圖形?
我必須在對應於rm = 8的所有點處添加垂直線,以查看網格的每個圖形中的數據傳播。我想知道: 1.我做錯了什麼。 2.一種更好的方式找到/代表的數據點,其中RM = 8
library(ggplot2)
library(reshape2)
library(MASS)
library(data.table)
data("Boston")
Boston <- as.data.table(Boston)
molten_boston <- Boston[, `:=`(rm = round(rm),
nox = nox * 100,
chas = chas * 10)]
molten_boston <- melt(data = molten_boston, id.vars = "rm")
comments_bar <- ggplot(molten_boston) +
geom_bar(binwidth = 1, aes(x = value), color = "black", fill = "salmon") +
# geom_vline(data = molten_boston[rm == 8, .SD, by = variable, .SDcols = "value"], aes(xintercept = value)) +
facet_wrap(~ variable, scales = "free")
print(comments_bar)
此代碼似乎產生預期的結果。你遇到了什麼錯誤? – jlhoward