0

I have sub-setted my data set so that only three sites are included, as I only want to plot three sites and the following code does not seem to work with ggplot. Anyone have any idea why?

rm(list=ls())
require(ggplot2)
require(reshape2)
require(magrittr)
require(dplyr)
require(tidyr)
setwd("~/Documents/Results")
mydata <- read.csv("Metals sheet R.csv")
L <- subset(mydata, Site =="B1"| Site == "B2"| Site == "B3", select =       c(Site,Date,Al))
L$Date <- as.Date(L$Date, "%d/%m/%Y")
ggplot(data=L, aes(x=Date, y=Al, xaxt="n", colour=Site)) +
geom_point() + 
labs(title = "Total Al in the Barlwyd and Bowydd
   19/03/2015.", x = "Site",
   y = "Total concentration (mg/L)") +
  scale_x_date(date_breaks = "1 month", labels = date_format("%m"))

It seems to falter after the ggplot line. Thanks in advance. I have double checked it but can't see anything wrong? I might possibly need a way to only plot three of my 21 sites.

The head of my subsetted L data set looks something like this (x58 reps)

Date          Site        Al
12/08/2015    B1         22.3
12/08/2015    B2         23.4
12/08/2015    B3         203

Thankyou in advance.

1 Answer 1

1

I think xaxt = "n" is wrong. The ggplot aes function is only for matching variables in your data to plot elements. To remove the x-axis text in ggplot, use the theme function e.g. ggplot2 plot without axes, legends, etc.

On a separate note, the %in% operator provides a quicker way of selecting a subset of values from a column:

subset(mydata, Site %in% c("B1", "B2", B3"))

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.