I am trying to plot a multi-element variation diagram and therefore have a discrete x axis and continuous y axis. I have two problems:
- although I have successfully used similar code before, the geom_path command is not plotting anything
- the geom_point function is plotting the wrong data. The first point should be 212 but is plotting <10
I have tried two different layouts of the data and code which I have included below but each results in the same image (attached).
Any help would be very much appreciated.
Holly
Data set sample 1:
Chond_normalised <- structure(list(Element = c("Th", "Nb", "La", "Ce", "Pr", "Nd", "Sm", "Zr", "Eu", "Ti", "Gd", "Tb", "Dy", "Th", "Nb", "La", "Ce", "Pr", "Nd", "Sm", "Zr", "Eu", "Ti", "Gd", "Tb", "Dy", "Th", "Nb", "La", "Ce", "Pr", "Nd", "Sm", "Zr", "Eu", "Ti", "Gd", "Tb", "Dy"), ppm = c(212, 65, 73, 49, 38, 26, 12, 25, 6, 6, 7, 6, 5, 8, 10, 122, 95, 73, 55, 26, 4, 17, 1, 14, 9, 7, 41, 46, 74, 57, 49, 43, 28, 19, 20, 6, 18, 13, 9), Sample = c("a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "a", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "b", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c", "c")), .Names = c("Element", "ppm", "Sample"), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L), class = "data.frame")
Chond_normalised
Code 1:
library(ggplot2)
Chond_normalised <- read.csv('filename.csv', header=TRUE, sep=",")
attach(Chond_normalised)
ggplot(data=Chond_normalised, aes(ymin=0.1, ymax=1000, x=Element, y=ppm)) +
geom_path(data=Chond_normalised, aes(y=ppm[Sample=="a"], x=Element[Sample=="a"]), colour="black", size=1.0) +
geom_point(data=Chond_normalised, aes(y=ppm[Sample=="a"], x=Element[Sample=="a"]), colour="red", size=1.0) +
scale_y_log10("Sample / Chondrite", breaks=c(0.1, 1, 10, 100, 1000)) +
scale_x_discrete("", labels=Element)
Data set sample 2:
Chond_normal <- structure(list(Element = c("Th", "Nb", "La", "Ce", "Pr", "Nd", "Sm", "Zr", "Eu", "Ti", "Gd", "Tb", "Dy"), a = c(212, 65, 73, 49, 38, 26, 12, 25, 6, 6, 7, 6, 5), b= c(8, 10, 122, 95, 73, 55, 26, 4, 17, 1, 14, 9, 7)), .Names = c("Element", "a", "b"), row.names = c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L), class = "data.frame")
Chond_normal
Code 2:
library(ggplot2)
Chond_normal <- read.csv('file.csv', header=TRUE, sep=",")
attach(Chond_normal)
ggplot(data=Chond_normal, aes(ymin=0.1, ymax=1000, x=Element, y=Chond_normal[,2:26])) +
geom_path(data=Chond_normal, aes(y=a, x=Element), colour="black", size=1.0) +
geom_point(data=Chond_normal, aes(y=a, x=Element), colour="red", size=1.0) +
scale_y_log10("Sample / Chondrite", breaks=c(0.1, 1, 10, 100, 1000)) +
scale_x_discrete("", labels=Element)