Я пытаюсь реплицировать Fivethirtyeight's Tarantino movie plot. Этот график использует ggplot2's dotplot
. Данные можно найти here.Значения оси Y по оси ggplot2
Мой код выглядит следующим образом:
tara <- read.csv("tarantino.csv")
dim(tara)
names(tara)
table(tara$movie)
rd <- subset(tara, movie=="Reservoir Dogs")
du <- subset(tara, movie=="Django Unchained")
ib <- subset(tara, movie=="Inglorious Basterds")
jb <- subset(tara, movie=="Jackie Brown")
kb1 <- subset(tara, movie=="Kill Bill: Vol. 1")
kb2 <- subset(tara, movie=="Kill Bill: Vol. 2")
pf <- subset(tara, movie=="Pulp Fiction")
plot1 <- ggplot(rd, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() + theme(legend.position="none") +
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
ggtitle(" RESERVIOR DOGS") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("")
plot2 <- ggplot(pf, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() +theme(legend.position="top")+
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
theme(legend.position="none") +
ggtitle(" PULP FICTION") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("")
plot3 <- ggplot(du, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() +theme(legend.position="top")+
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
theme(legend.position="none") +
ggtitle(" DJANGO UNCHAINED") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("")
plot4 <- ggplot(ib, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() +theme(legend.position="top")+
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
theme(legend.position="none") +
ggtitle(" INGLORIOUS BASTARDS") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("")
plot5 <- ggplot(jb, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() +theme(legend.position="top")+
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
theme(legend.position="none") +
ggtitle(" JACKIE BROWN") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("")
plot6 <- ggplot(kb1, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() +theme(legend.position="top")+
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
theme(legend.position="none") +
ggtitle(" KILL BILL: VOL 1") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("")
plot7 <- ggplot(kb2, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() +theme(legend.position="none")+
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
ggtitle(" KILL BILL: VOL 2") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("minutes")
library(grid)
grid.newpage()
pushViewport(viewport(layout = grid.layout(7, 1)))
vplayout <- function(x, y)
viewport(layout.pos.row = x, layout.pos.col = y)
print(plot1, vp = vplayout(1, 1))
print(plot2, vp = vplayout(2, 1))
print(plot3, vp = vplayout(3, 1))
print(plot4, vp = vplayout(4, 1))
print(plot5, vp = vplayout(5, 1))
print(plot6, vp = vplayout(6, 1))
print(plot7, vp = vplayout(7, 1))
Результат выглядит следующим образом:
Участок имеет несколько вопросов:
- Y оси неуправляем. Я могу использовать
coord_fixed(ratio=X)
; но это не очень помогает. - Точки не одного размера. Я попытался использовать
dotsize
; но он не работает. - Не удалось сохранить фон
grey
в легендах.
Ваш код не очень DRY. Используйте 'facet_grid', и ggplot будет поддерживать масштабирование. Однако у него есть другой взгляд, который вам может понадобиться, чтобы заставить вас входить в то, что вы хотите. – alistaire
@alistaire, что означает «СУХИЕ». Он очень похож на мой код: P Согласитесь с вами о 'facet_grid'. – Mist
Что вы имеете в виду с неуправляемой осью y? Вы сами устанавливаете лимиты ... – Heroka