x axis labels being cut off only when saving graph in r
10,816
Starting up a new graphics device resets the par values to the device defaults so you need to set mar after calling png:
png("~/graph.png") ; par(mar=c(6, 4, 4, 2) + 0.1)
barplot(df, beside=TRUE, ylim=c(0,100),
ylab="Percentage of Positive Answers ", space=.1, main="Some Title",
names.arg=c("Captivate", "Challenge", "Clarify", "Confer", "Consolidate", "Care", "Control", "Engagement"), las=2, axis.lty=1)
dev.off()
Author by
user2460499
Updated on June 04, 2022Comments
-
user2460499 almost 2 years
I am attempting to create a bargraph in r, and I am having trouble with the x axis labels being cut off. However this is only happening when I save the graph to a file. If I print it to the graphics device it shows all of the labels, however when I save the file the labels are cut off.
Here is code that reproduces the problem.
Captivate<-51.38 Challenge<-88.88889 Clarify<-80.55556 Confer<- 81.29085 Consolidate<-64.81481 Care<-68.51852 Control<-70.66993 Engagement<-66.17239 df<-rbind(Captivate, Challenge, Clarify, Confer, Consolidate, Care, Control, Engagement) png("~/graph.png") barplot(df, beside=TRUE, ylim=c(0,100),ylab="Percentage of Positive Answers ", space=.1, main="Some Title", names.arg=c("Captivate", "Challenge", "Clarify", "Confer", "Consolidate", "Care", "Control", "Engagement"), las=2, axis.lty=1) dev.off()
I have tried changing the margins using par() however nothing has worked.
Can anyone tell me what I need to do to have the full labels showing?