Reputation: 339
I'm doing a Box Plot in R, and I want to label my Y axis. The names are quite long, so I want to make the bottom margin bigger to fit them all in. I'm told that what I need to do is use the mar()
function. But it seems that no matter what values I put into the function, my margins never change!
My box plot looks like this:
My R Script looks like this:
boxplot(
as.numeric(UEC$Q1_1)[3:21],
as.numeric(UEC$Q1_2)[3:21],
as.numeric(UEC$Q1_3)[3:21],
as.numeric(UEC$Q1_4)[3:21],
as.numeric(UEC$Q1_5)[3:21],
as.numeric(UEC$Q1_6)[3:21],
as.numeric(UEC$Q1_7)[3:21],
as.numeric(UEC$Q1_8)[3:21],
as.numeric(UEC$Q1_9)[3:21],
as.numeric(UEC$Q1_10)[3:21],
as.numeric(UEC$Q1_11)[3:21],
as.numeric(UEC$Q1_12)[3:21],
as.numeric(UEC$Q1_13)[3:21],
as.numeric(UEC$Q1_14)[3:21],
as.numeric(UEC$Q1_15)[3:21],
as.numeric(UEC$Q1_16)[3:21],
as.numeric(UEC$Q1_17)[3:21],
as.numeric(UEC$Q1_18)[3:21],
as.numeric(UEC$Q1_19)[3:21],
as.numeric(UEC$Q1_20)[3:21],
as.numeric(UEC$Q1_21)[3:21],
as.numeric(UEC$Q1_22)[3:21],
as.numeric(UEC$Q1_23)[3:21],
as.numeric(UEC$Q1_24)[3:21],
as.numeric(UEC$Q1_25)[3:21],
as.numeric(UEC$Q1_26)[3:21],
main="UEC Questions",
names=c("annoying/enjoyable", "not understandable/understandable", "creative/dull", "easy to learn/difficult to learn", "valuable/inferior", "boring/exciting", "not interesting/interesting", "unpredictable/predictable", "fast/slow", "inventive/conventional", "obstructive/supportive", "good/bad", "complicated/easy", "unlikable/pleasing", "usual/leading edge", "unpleasant/pleasant", "secure/not secure", "motivating/demotivating", "meets expectations/does not meet expectations", "inefficient/efficient", "clear/confusing", "impractical/practical", "organized/cluttered", "attractive/unattractive", "friendly/unfriendly", "conservative/innovative"),
las=2,
mar=c(5.1, 4.1, 4.1, 2.1)
)
I know the values I've put in for margins are probably wrong, but they're not working anyway!
Can anyone suggest where I am going wrong?
Upvotes: 1
Views: 2078
Reputation: 8364
You can use par
before the call to boxplot
.
With cex.axis
you can lower the font size of the x-axis, and with mar
you can mess around with the spacing around the border.
Note the order is mar=c("bottom-side", "left-side", "upper-side", "right-side")
.
par(cex.axis=0.8, mar=c(8, 4, 5, 2))
boxplot(as.numeric(data$qsec),
as.numeric(data$mpg),
names = c("areallylongtext", "anotherreallylongtext"), las=2)
Please note that you shouldn't copy/paste all those as.numeric()
, you should instead use a grouping variable like in my example below:
par(cex.axis=0.8, mar=c(10, 4, 5, 2))
boxplot(mpg ~ cyl, data,
names=c("areallylongtext", "anotherreallylongtext", "yetanotherreallylongtext"), las=2)
Upvotes: 2