How To Make A Plot In R For Binary Data
[This article was first published on Methods – finnstats, and kindly contributed to R-bloggers]. (You can report upshot most the content on this page here)
Want to share your content on R-bloggers? click hither if you have a blog, or here if you don't.
Plot Categorical Information in R, Categorical variables are data types that tin can be separated into categories. Race, sex, age grouping, and educational level are examples of chiselled variables.
This tutorial describes three approaches to plot categorical data in R.
Let's make utilise of Bar Charts, Mosaic Plots, and Boxplots past Group.
Approach ane: Bar Chart
The code below demonstrates how to brand a bar nautical chart to correspond the frequency of teams in a given information frame. Let's load the library first,
Timeseries assay in R » Decomposition, & Forecasting »
library(ggplot2)
Create dataset
data <- information.frame(result = c('West', 'L', 'L', 'W', 'W', 'L', 'L', 'L', 'W', 'L'), squad = c('B', 'D', 'B', 'A', 'D', 'A', 'A', 'D', 'C', 'D'), score = c(18, 38, 29, 28, 32, 55, 22, 48, 33, 12), rebounds = c(15, 5, 9, 10, 15, 8, 9, 12, 11, 10)) caput(information) result team score rebounds i W B xviii 15 2 L D 38 5 3 L B 29 9 4 W A 28 10 v West D 32 xv 6 50 A 55 8
Create a bar chart of teams
ggplot(data, aes(x=reorder(team, team, part(x)-length(x)))) + geom_bar(fill='red') + labs(x='Team')
datatable editor-DT parcel in R » Shiny, R Markdown & R »
Approach ii: Boxplots past Group
A useful technique to show a numeric variable that is grouped by a categorical variable is to utilise grouped boxplots.
The post-obit code, explains how to brand boxplots that display the distribution of points scored per team
Create boxplots of points, grouped past team
ggplot(data, aes(x=squad, y=score)) + geom_boxplot(make full='green')
The teams are represented on the x-axis, while the distribution of points scored past each team is represented on the y-centrality.
Kruskal Wallis test in R-One-style ANOVA Culling »
Arroyo 3: Mosaic Plot
A mosaic plot is a form of a graph that shows the frequencies of 2 categorical variables on the same graph.
The following lawmaking demonstrates how to make a mosaic plot that displays the frequency of the chiselled variables "result" and "team" in ane figure
Create the counts
counts <- table(data$result, data$team)
#create a mosaic plot
mosaicplot(counts, xlab='Match Result', ylab='Team',main='Wins by Squad', col='orangish')
The game result is displayed on the x-centrality, while the iv carve up teams are displayed on the y-axis.
Principal component assay (PCA) in R »
The post How to Plot Categorical Data in R-Quick Guide appeared beginning on finnstats.
How To Make A Plot In R For Binary Data,
Source: https://www.r-bloggers.com/2021/08/how-to-plot-categorical-data-in-r-quick-guide/
Posted by: wattshaved1952.blogspot.com
0 Response to "How To Make A Plot In R For Binary Data"
Post a Comment