knitr::opts_chunk$set(echo = TRUE)
library(knitr)
library(foreign)
## How-to Graph
# Load Data ####
library(haven)
IV <- read_spss("C:/Users/monteangel/Desktop/SPSS_Data_V1.1.sav")
## Load libraries: tidyverse, ggplot
library(tidyverse)
## -- Attaching packages ----------------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v ggplot2 3.2.1 v purrr 0.3.3
## v tibble 2.1.3 v dplyr 0.8.3
## v tidyr 1.0.0 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## -- Conflicts -------------------------------------------------------------------------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(ggplot2)
## Density plot + points
ggplot(IV,
aes(x = PTGISF_Total,
y = CESSF_Total)) +
stat_density_2d(aes(fill = ..level..),
geom = "polygon") +
geom_point(color = "orange") +
scale_fill_gradient(low = "pink",
high = "cyan") +
labs(title = "Correlation of PTG and CES Scores")
## Warning: Removed 30 rows containing non-finite values (stat_density2d).
## Warning: Removed 30 rows containing missing values (geom_point).

## Density plot + points
ggplot(IV,
aes(x = PTGISF_Total,
y = CESSF_Total)) +
stat_density_2d(aes(fill = ..level..),
geom = "polygon") +
geom_point(color = "orange") +
scale_fill_gradient(low = "pink",
high = "cyan") +
labs(title = "Correlation of PTG and CES Scores")
## Warning: Removed 30 rows containing non-finite values (stat_density2d).
## Warning: Removed 30 rows containing missing values (geom_point).

## Raster geom
ggplot(IV,
aes(x = PTGISF_Total,
y = CESSF_Total)) +
stat_density_2d(geom = "raster",
aes(fill = ..density..),
contour = FALSE) +
scale_fill_gradient(low = "navy blue",
high = "hot pink") +
labs(title = "Density Plot (Raster) of CES and PTG Scores")
## Warning: Removed 30 rows containing non-finite values (stat_density2d).

## Hexagon geom
ggplot(IV,
aes(x = PTGISF_Total,
y = CESSF_Total)) +
geom_hex() +
scale_fill_gradient(low = "navy blue",
high = "cyan") +
labs(title = "Hexagon Plot of PTG and CES Scores")
## Warning: Removed 30 rows containing non-finite values (stat_binhex).

## Scatterplot and Smoother
ggplot(IV,
aes(x = PTGISF_Total,
y = CESSF_Total)) +
geom_point() +
geom_smooth() +
labs(title = "Scatterplot and Smoother of PTG and CES Scores") +
theme_dark()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 30 rows containing non-finite values (stat_smooth).
## Warning: Removed 30 rows containing missing values (geom_point).
