ggplot2 を使用して簡単なステップ プロットを作成しています。ファイルの種類を PNG から PDF に切り替えると、プロットにラベル、目盛り、タイトル、凡例が表示されません。私が間違っていることは何ですか?
データ:
plotData <- structure(list(iteration = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), time = c(0L, 10L,
20L, 30L, 40L, 50L, 60L, 70L, 80L, 90L, 100L, 0L, 10L, 20L, 30L,
40L, 50L, 60L, 70L), routes = c(6L, 6L, 5L, 3L, 3L, 3L, 3L, 3L,
2L, 1L, 0L, 5L, 5L, 5L, 5L, 1L, 1L, 1L, 0L)), .Names = c("iteration",
"time", "routes"), class = "data.frame", row.names = c(NA, -19L
))
コード:
library(ggplot2)
x_axis_breaks <- seq(10, 100, by = 10)
png(file="plot.png",width=1280, height=1280)
## pdf(file="plot.pdf",width=6,height=6)
plot <- ggplot(plotData) + geom_step(data=plotData, size = 5,
mapping=aes(x=time,
y=routes, group=iteration, colour=factor(iteration)), direction="vh")
plot <- plot + scale_x_discrete(breaks=x_axis_breaks, name="time") +
scale_y_discrete(name="#routes");
plot <- plot + opts(axis.text.x=theme_text(size=36,face="bold"),
axis.text.y=theme_text(size=36,face="bold")) +
scale_colour_hue(name="iteration")
plot <- plot + opts(legend.title=theme_text(size=36,face="bold"),
legend.text=theme_text(size=36,face="bold"))
plot <- plot + opts(axis.title.x=theme_text(size=36,face="bold"),
axis.title.y=theme_text(size=36,face="bold"))
plot <- plot + opts(title="network lifetime",
plot.title=theme_text(size=36, face="bold"))
print(plot)
dev.off()
「png...」から「pdf」に切り替えると、問題が発生します。データ自体はうまくプロットされています。ggplot2 で PDF プロットを生成するための情報が不足しているのかもしれません。