By running the following code, I can receive the saved PNG in the file location. According to the modified time, they are generated by this execution of code. When I try to merge this two PNG into one plot, I found the error message:
multiplot(plot1, plot2, cols = 2)
Error: Aesthetics must be either length 1 or the same as the data (14): x, y
And I can't load the plot1 and plot2 in the plot section in RStudio.
dat <- fread('IG_post.csv')
plot1 <- ggplot(dat, aes(x = dat$Parameter, y = dat$Mean)) +
geom_point(size = 2) +
geom_errorbar(width = 0.1, aes(ymax = dat$`0.975`, ymin = dat$`0.025`)) +
geom_hline(yintercept = 0, col = 'blue') +
labs(x='beta', y='value', title = 'Zero-inflated Gamma Model') +
theme_bw()+ theme(axis.text.x=element_text(angle=45, hjust=1), plot.title = element_text(hjust = 0.5))
file_name <- paste0('C:/Users/Qiangsuper/Dropbox/Papers/1/plot/IG_post.png')
png(filename = file_name, width = 1200, height = 600, res = 240)
plot1
dev.off()
dat <- fread('Tweedie_post.csv')
plot2 <- ggplot(dat, aes(x = dat$Parameter, y = dat$Mean)) +
geom_point(size = 2) +
geom_errorbar(width = 0.1, aes(ymax = dat$`0.975`, ymin = dat$`0.025`)) +
geom_hline(yintercept = 0, col = 'blue') +
labs(x='beta', y='value', title = 'Tweedie Model') +
theme_bw()+ theme(axis.text.x=element_text(angle=45, hjust=1), plot.title = element_text(hjust = 0.5))
file_name <- paste0('C:/Users/Qiangsuper/Dropbox/Papers/1/plot/Tweedie_post.png')
png(filename = file_name, width = 1200, height = 600, res = 240)
plot2
dev.off()
file_name <- paste0('C:/Users/Qiangsuper/Dropbox/Papers/1/plot/post.png')
png(filename = file_name, width = 1200, height = 600, res = 240)
multiplot(plot1, plot2, cols = 2)
dev.off()
Please help me to figure out where I went wrong. Thank you very much for your help.