psoares
psoares

Reputation: 4883

Not able to decrease size of legend box R

I'm trying to display 4 plots in the same device window in R. I'm using Linux. However my output is far from pleasant to view.

enter image description here

As you can see the legend box is quite huge compared the size of the plot. I'm trying to decrease the size of the box; however I'm not able to do it. I've tried positioning the legend, box.lwd, cex, none of those gave me what I wanted.

Can anyone give me some pointers on how to decrease the size of the box of the legend?

Here is my R code:

require survival

survspec <- survfit(Surv(data1$YearEvent, data1$status) ~ data1$Vac, data1)
par(mfrow=c(2,2))
plot(survspec,  mark.time=FALSE,  xlab="Time (in years)", ylim=c(0.7, 1), 
     ylab="S(t)", col=c("royalblue", "violetred", "seagreen"))
legend(x="left",legend=c("Yes", "No", "NA"), lty=c(1, 1, 1), 
       col=c("royalblue", "violetred", "seagreen"))

The variable YearEvent corresponds to the x axis while the variable status is 0 or 1 and Vac can take three values. It's a Kaplan Meier plot, mainly used in survival analysis

Upvotes: 2

Views: 7193

Answers (2)

Yogi
Yogi

Reputation: 9

Please have a look at y.intersp parameter in legends() function. Thanks!

Upvotes: 0

Carl Witthoft
Carl Witthoft

Reputation: 21532

All you need to do is use the cex set of parameters in your legend command. That will reduce the font size and I believe the symbol size (although you aren't displaying any symbols in this particular case), and thus the entire size of the legend box.

See ?par for details.

Upvotes: 1

Related Questions