) and dev.off() to write plots into files. The code is like this
allWeeks = data.frame(weekInYear = 1:53,
user2013 = sample(1:100, 53),
user2014 = sample(1:100, 53),
user2015 = sample(1:100, 53),
job2013 = sample(1:100, 53),
job2014 = sample(1:100, 53),
job2015 = sample(1:100, 53))
allWeeks[30:53, c('user2015', 'job2015')] = NA
melted = melt(allWeeks[ , c('weekInYear', 'user2015', 'job2015')], id = 'weekInYear')
pic1 = 'output/allWeek2015.png'
png(width = 600, height = 300, file = pic1)
ggplot(melted, aes(weekInYear, value, colour = variable)) +
geom_line()
dev.off()
melted = melt(allWeeks[ , c('weekInYear', 'user2013', 'user2014', 'user2015')], id = 'weekInYear')
pic2 = 'output/allWeekUser.png'
png(width = 600, height = 300, file = pic2)
ggplot(melted, aes(weekInYear, value, colour = variable)) +
geom_line()
dev.off()
melted = melt(allWeeks[ , c('weekInYear', 'job2013', 'job2014', 'job2015')], id = 'weekInYear')
pic3 = 'output/allWeekJob.png'
png(width = 600, height = 300, file = pic3)
ggplot(melted, aes(weekInYear, value, colour = variable)) +
geom_line()
dev.off()
When I select all of the code and click run, it works well, with some warning messages about NAs in plotted data.
When I click source
, there's no message, and the pictures are blank. Any help's appreciated please...
UPDATE:
replaced with ggsave(pic1, width = 3, height = 1.5)
and there's no blank issue now. But ggsave()
seems to use an unreasonable scale and fontsize... See pictures: LEFT saved with png()
and dev.off()
vs. RIGHT saved with ggsave()
. Did I miss some parameter? Any help's appreciated please