forked from CamEJ/Simple-plots-in-R
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathScatter plots
41 lines (31 loc) · 1 KB
/
Scatter plots
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Scatter plots
# Example data: "scatter.txt" (tab separated)
Week pH Treatment Location
0 5.58 Zero Soil
2 5.245 Zero Rhizo
4 5 Zero Soil
5 4.9025 Zero Soil
0 4.9 Zero Rhizo
2 4.85 Zero Rhizo
4 4.845 Zero Rhizo
5 5.1375 Zero Soil
0 5.17 High Soil
2 5.0425 High Soil
4 5.3025 High Rhizo
5 5.155 High Rhizo
6 5.6275 High Soil
# ie four variables: week, pH, treatment, location
# libraries needed:
library(ggplot2)
# read in table from wkdir
data <- read.table("scatter.txt", header = TRUE, , sep='\t')
k <- ggplot(data, aes(x=Week,y=pH, color = Treatment)) +
geom_point(aes(shape=Location),
size = 4)
k # print and check
# change colours
k2 <- k + scale_color_brewer(palette="Set1") + theme_bw() + theme(text = element_text(size=12, color = "black"))
## now add axis labels and title
k3 <- k2 + labs(title = "pH change with time in High & Zero Plots")
## Editing title to make space beneath it and to change size and font face
k3 + theme(plot.title = element_text(size=12, face="bold", vjust=2))