Two basic scatter plots:
Plot a, shows total antidepressant usage in Scandinavia: 2007-2017, M&F, 5-19yrs old.
Plot b, shows the same as plot a, with the age groups displayed in different colours.
# Plot a - Basic plot
# Load packages
pacman::p_load(pacman,tidyverse,GGally,ggthemes,ggvis,httr,plotly,rio,rmarkdown,shiny,ggplot2)
c1 <- read.csv("census.csv") # c1 variable becomes selected csv file
head(c1) # Shows first 6 lines of selected csv file, to see column attribute names, for plot (x,y)
## year sex age cnt country
## 1 2007 F 5-9 164148 DK
## 2 2007 F 10-14 171864 DK
## 3 2007 F 15-19 157037 DK
## 4 2007 M 5-9 172068 DK
## 5 2007 M 10-14 181190 DK
## 6 2007 M 15-19 165784 DK
plot(c1$year, c1$cnt, # plot selected attributes with colour and labels
col="red",
pch=19, # Use solid circles for points
main="Antidepressant use in Scandinavia: 5-19yrs old.", # Main title
xlab="Year", # x axis label
ylab="Number of users.") # y axis label
# Plot b - Scatter plot
# Load packages
pacman::p_load(pacman,tidyverse,GGally,ggthemes,ggvis,httr,plotly,rio,rmarkdown,shiny,ggplot2)
c1 <- read.csv("census.csv") # c1 variable becomes selected csv file
head(c1) # Shows first 6 lines of selected csv file, to see column attribute names,for plot (x,y) and colour selection
## year sex age cnt country
## 1 2007 F 5-9 164148 DK
## 2 2007 F 10-14 171864 DK
## 3 2007 F 15-19 157037 DK
## 4 2007 M 5-9 172068 DK
## 5 2007 M 10-14 181190 DK
## 6 2007 M 15-19 165784 DK
ggplot(data=c1,aes(x=year,y=cnt))+geom_point(aes(color=age))
# ggplot uses data from c1 to plot x and y attributes and plots the different y variables from chosen attribute in different colours