A data frame with 50 observations on 2 variables.
[,1] speed numeric Speed (mph) [,2] dist numeric Stopping distance (ft) Source
Ezekiel, M. (1930) Methods of Correlation Analysis. Wiley.
McNeil, D. R. (1977) Interactive Data Analysis. Wiley.
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.4.4
data("cars")
data<-cars
plot(data)#basic r-plot
Lets make it publication ready
library(ggpubr)
## Warning: package 'ggpubr' was built under R version 3.4.4
## Loading required package: magrittr
sp <- ggscatter(data, x = "dist", y = "speed", #mention data and axis
add = "reg.line", # Add regression line
add.params = list(color = "red", fill = "lightgray"), # Customize regression line
conf.int = TRUE # Add confidence interval
)+ stat_cor(method = "pearson", label.x = 3, label.y = 30)# Add correlation coefficient
sp
Let us fix the axis lables and titles
sp1<-ggpar(sp,xlab = "Speed (mph)",ylab = "Distance (ft)",main = "Correlation between car speed and stopping distance",
font.main = c(14, "bold", "black"),
font.x=c(12,"bold"),
font.y = c(12,"bold"))#making font bold and beautiful
sp1
Alboukadel Kassambara (2018). ggpubr: ‘ggplot2’ Based Publication Ready Plots. R package version 0.2. https://CRAN.R-project.org/package=ggpubr
H. Wickham. ggplot2: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016.