#15 Alkali Silica Template
[This article was first published on Darren Wilkinson » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Does what it says on the tin.
#------------------------------ #-------- INFORMATION --------- #------------------------------ # Plotting points from Hugh # Rallinson's "Using Geochemical # Data" book. Code compiled by # Darren J. Wilkinson, # Grant Inst. Earth Science # The University of Edinburgh # [email protected] #------------------------------ # -------- CONTROLS ---------- y.max = 16 x.min = 35 x.max = 80 lab.size = 5 save = "/Users/s0679701/Desktop/" filename = "test.png" #------------------------------ # -------- LIBRARIES ---------- library (grid) library (scales) library (ggplot2) #------------------------------ # -------- DON'T EDIT ---------- a = c(1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8) x = c(41.0,41.0,52.5,50.0,52.5,57.6,63.0,63.0,45.0,45.0,61.0,63.5,45.0,52.0,57.0,63.0,69.0,45.0,49.4,52.0,52.0, 48.4,53.0,57.0,57.0,69.0,69.0,76.6,41.0,45.0) y = c(0.500,7.000,14.000,15.126,14.000,11.700,7.000,0.500,0.500,5.000,13.500,14.830,5.000,5.000,5.900, 7.000,8.000,9.400,7.300,5.000,0.500,11.500,9.300,5.900,0.500,12.500,8.000,0.500,3.000,3.000) lines = data.frame (a, x, y) b = c("Picro-Basalt", "Basalt", "Basaltic Andesite", "Andesite", "Dacite", "Basanite", "Trachy Basalt", "Basaltic Trachyandesite", "Trachyandesite", "Trachydacite", "Rhyolite", "Tephrite", "Phonotephrite", "Tephriphonolite", "Trachyte", "Foidite", "Phonolite") c = c(1:17) x = c(43, 48.5, 54.5, 60, 68, 43, 48.75, 53, 57.5, 65, 75, 46, 49, 53, 65, 45, 58) y = c(2, 2.5, 3, 3.5, 4, 6, 5.5, 6.5, 8.5, 9, 8, 8, 9.5, 11.5, 12, 13, 14) labels = data.frame (b, x, y) x = c(39.8,65.5) #MacDonald (1968) y = c(0.35, 9.7) #MacDonald (1968) sub = data.frame (x, y) #------------------------------ # -------- BEGIN PLOT ---------- ggplot (lines, aes (x=x, y=y)) + # Field Boundaries geom_line ( aes(linewidth = factor (a)) ) + # Alkaline-Tholeiitic Line geom_line ( data = sub, aes (x=x, y=y), linetype = "longdash" ) + # Field Labels geom_text ( data = labels, aes(x = x, y = y, label = b), size = lab.size ) + scale_x_continuous ( name = (expression(paste("SiO"["2"], " (wt. %)"))), limits = c(x.min, x.max) ) + scale_y_continuous ( name = (expression(paste("Na"["2"], "O + K"["2"], "O", " (wt. %)"))), breaks = c(seq(0, y.max, 2)), limits = c(0, y.max) ) + theme ( plot.title = element_text (vjust = 3, size = 20), #plot title plot.margin = unit (c(3, 3, 3, 3), "lines"), #adjust the margins of the entire plot panel.border = element_rect (colour = "black", fill = F, size = 2), #change the colour of the axes to black panel.grid.major = element_blank (), # remove major grid panel.grid.minor = element_blank (), # remove minor grid panel.background = element_rect (fill = "white"), #makes the background transparent (white) NEEDED FOR INSIDE TICKS legend.background = element_rect (fill = "white"), legend.justification=c(1, 1), legend.position = c(1, 1), # put the legend INSIDE the plot area legend.key = element_blank (), # switch off the rectangle around symbols in the legend legend.title = element_blank (), # switch off the legend title legend.text = element_text (size = 15), #sets the attributes of the legend text axis.title.x = element_text (vjust = -2, size = 20), #change the axis title axis.title.y = element_text (vjust = -0.1, angle = 90, size = 20), #change the axis title axis.text.x = element_text (size = 17, vjust = -0.25, colour = "black"), #change the axis label font attributes axis.text.y = element_text (size = 17, hjust = 1, colour = "black"), #change the axis label font attributes axis.ticks = element_line (colour = "black", size = 0.5), #sets the thickness and colour of axis ticks axis.ticks.length = unit(-0.25 , "cm"), #setting a negative length plots inside, but background must be FALSE colour axis.ticks.margin = unit(0.5, "cm") # the margin between the ticks and the text ) ggsave (paste (save, filename), height = 12, width = 18, dpi = 75)
To leave a comment for the author, please follow the link and comment on their blog: Darren Wilkinson » R.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.