Skip to content

Data Visualization 

kirkvanacore edited this page May 24, 2021 · 1 revision

Scatter Plot 

#simple
plot(x=df$var, y=df$var, main="Title of Graph", xlab="X Axis Label", ylab="Y Axis Label")

#more elaborate/customizable
ggplot(data, aes(x=v1, y=v2)) +
		geom_point() +
        ggtitle("title")+
        xlab("label") +
        ylab("label") +
        theme_minimal()


ggMarginal(scatter_object, type = "histogram")

Box Plot 

#simple
boxplot(df$var, main ="Title Your Graph", ylab = "Y Axis Label")
CrossTab/Contingency Table
#from package gmodels
CrossTable(x=df$var, y=df$var, chisq=TRUE)

Histogram

#Simple
hist(df$var, main="Title Your Histogram", xlab = "X Axis Label")

#More Elaborate
require(ggplot2)
require(ggExtra)
# DF = dataframe 
# X= Variable to hisogram
# Y= catagorical Variable to be a color detail

ggplot(DF, aes(x=X, fill = as.factor(Y))) + 
               geom_histogram() +
                scale_fill_brewer(palette = "Set2") +
                ggtitle("Main Title")+
                xlab("X axis title") +
                ylab("Count of... title") +   
                labs(fill = "Leg title") +
                theme_minimal()
Bar Graph (count of X)
require(ggplot2)
require(ggExtra)
# DF = dataframe 
# X= Variable to hisogram

Bar representing count of a cat variable

ggplot(db, aes(x = x)) +
  geom_bar() +
  ggtitle("Main Title")+
  xlab("X axis title") +
  ylab("Count of... title") +  
  geom_text(stat='count', aes(label=..count..), vjust=-1) +
  coord_cartesian(ylim = c(0, 100001)) +
  theme_minimal()

Bar representing variable values

ggplot(db, aes(x = x, y= y)) +
  geom_col() +
  ggtitle("Main Title")+
  xlab("X axis title") +
  ylab("Count of... title") + 
  geom_text(aes(label=Effect_Size), vjust=-1) +
  theme_minimal()
Correlation matrix visualization
require(corrpolot)
require(Hmisc) 

Corration Matrix

# select variables to correlate correlations 
    Corr_data <- bent[, c("list of variables")]
# clean names for 
    colnames(Corr_data) <- c("variables and names are displayed in ")
     
    Corr <- rcorr(as.matrix(Corr_data))

    corrplot(Corr$r,
             type = "lower",
             method =  "color",
             tl.col = "black",
             tl.srt = 360,
             p.mat = Corr$P,
             addCoef.col = "black",
             number.cex = 2,
             tl.cex = 2,
             sig.level = .05)

lots of additional info on corrplot for the viz here: https://cran.r-project.org/web/packages/corrplot/vignettes/corrplot-intro.html

Clone this wiki locally