Я относительный новичок R/ggplot2, и я хочу создать следующий ниже график, чтобы ось y рассчитывалась независимо для каждой грани. Например, я хотел бы, чтобы период 1-го периода по оси Y был просто рассчитан по данным, фазированным по периоду времени1, а проценты периода времени 2 были рассчитаны по данным, фазированным по периоду времени. 2.ggplot2 - вычисления фасетов и отдельных y-координат
В настоящее время, он вычисляет их все вместе.
Вот мой текущий код:
library(ggplot2)
### create data - Time Period 1
weapons <- rep(1, length = 31)
weapons <- c(weapons, rep(2, length = 9))
weapons <- c(weapons, rep(3, length = 6))
weapons <- c(weapons, rep(4, length = 0))
weapons <- c(weapons, rep(5, length = 5))
weapons <- c(weapons, rep(6, length = 0))
weapons <- c(weapons, rep(7, length = 29))
time <- rep(1, length = 80)
### create data - Time Period 2
weapons <- c(weapons, rep(1, length = 13))
weapons <- c(weapons, rep(2, length = 0))
weapons <- c(weapons, rep(3, length = 1))
weapons <- c(weapons, rep(4, length = 0))
weapons <- c(weapons, rep(5, length = 3))
weapons <- c(weapons, rep(6, length = 0))
weapons <- c(weapons, rep(7, length = 7))
time <- c(time, rep(2, length = 24))
weapons <- factor(weapons, levels = 1:7, labels = c("Small Arms", "Heavy Machine Guns", "Mortars", "Recoilless Rifles", "107mm+ Rockets, Missiles", "MANPADs", "Unspecified"))
time <- factor(time, levels = 1:2, labels = c("Time Period 1", "Time Period 2"))
d <- data.frame(weapons, time)
ggplot(d, aes(x=weapons, y=(..count..) /sum (..count..), fill = (weapons))) + geom_bar() + geom_text(stat='count', aes(label=..count..), vjust = -1) + facet_grid(time ~ .) + coord_cartesian(ylim = c(0, .6))
Спасибо, это делает это точно !!!!! –