我可以帮您翻译以下内容,它与IT技术相关。您需要将简单的步骤绘图使用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图时缺少一些信息?
dev.off()
(尽管它没有出现在你的代码块中),但是这里的症状听起来很像忘记调用dev.off()
... - undefinedsessionInfo()
的结果吗? - undefinedggsave("plot.png")
。 - undefined