[R] Plotting legend outside of chart area

Peter Alspach Peter.Alspach at plantandfood.co.nz
Wed Jun 24 22:13:45 CEST 2015


Tena koe Samantha

You probably need to set some graphics parameters such as xpd and mar (see ?par), and then give the × and y location of the legend rather than 'bottomright' (see ?legend).

HTH ....

Peter Alspach

PS Please don't post in html (see the posting guide) ... P 

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Samantha Allcock
Sent: Thursday, 25 June 2015 4:35 a.m.
To: 'r-help at r-project.org'
Subject: [R] Plotting legend outside of chart area

Hello,

I am trying to add a legend to my PCA plot so that it looks neat. I think plotting this outside of the chart area would be good but I cannot seem to fathom the correct code for this. I wondered if anyone could help please?

The code I am using is as follows:

grp<- with(Matan, cut(R_category_no,14, labels=1:14)) cols <- c("grey0", "wheat", "red", "cyan", "orange", "darkolivegreen2", "purple3", "royalblue", "burlywood4", "orchid", "forestgreen", "green", "gray", "yellow1") plot(geopca, display="sites", scaling=3, type="n") points(geopca, display="sites", scaling=3, col=cols[grp], pch=16)

legend("bottomright", col=c("grey0", "wheat", "red", "cyan", "orange", "darkolivegreen2", "purple3", "royalblue", "burlywood4", "orchid", "forestgreen", "green", "gray", "yellow1"), c("Control type 1", "Control type 2", "External/Courtyard", "Midden", "Animal Occupation", "External fire installations and ashy deposits", "Internal fire installations and ashy deposits", "Hearth make-up", "Floors and surfaces", "Plasters and clay features", "Storage features", "Platforms and benches", "Mortars", "Roofs and roofing materials"), pch=16, cex=0.75, bty="n")

Thank you for your time in advance


Dr Samantha Lee Allcock
Faculty of Science and Technology
Department of Archaeology, Anthropology and Forensic Science Christchurch House Rm: C133 Bournemouth University Talbot Campus Poole
BH12 5BB
Tel: 01202 9(62474)

sallcock at bournemouth.ac.uk<mailto:sallcock at bournemouth.ac.uk>
research.bournemouth.ac.uk/2014/07/inea-project-2


BU is a Disability Two Ticks Employer and has signed up to the Mindful Employer charter. Information about the accessibility of University buildings can be found on the BU DisabledGo webpages This email is intended only for the person to whom it is addressed and may contain confidential information. If you have received this email in error, please notify the sender and delete this email, which must not be copied, distributed or disclosed to any other person. Any views or opinions presented are solely those of the author and do not necessarily represent those of Bournemouth University or its subsidiary companies. Nor can any contract be formed on behalf of the University or its subsidiary companies via email.

	[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
The contents of this e-mail are confidential and may be ...{{dropped:14}}



More information about the R-help mailing list