


Mosaicplot(counts, xlab=' Game Result', ylab=' Team',
CPLOT IN R HOW TO
Example 3: Mosaic PlotĪ mosaic plot is a type of plot that displays the frequencies of two different categorical variables in one plot.įor example, the following code shows how to create a mosaic plot that shows the frequency of the categorical variables ‘result’ and ‘team’ in one plot: #create data frame The x-axis displays the teams and the y-axis displays the distribution of points scored by each team. #create boxplots of points, grouped by team Grouped boxplots are a useful way to visualize a numeric variable, grouped by a categorical variable.įor example, the following code shows how to create boxplots that show the distribution of points scored, grouped by team: library(ggplot2) Ggplot(df, aes(x= reorder(team, team, function(x)- length(x)))) + We can also use the following code to order the bars in the chart from largest to smallest: #create bar chart of teams, ordered from large to small The x-axis displays each team name and the y-axis shows the frequency of each team in the data frame. The following code shows how to create a bar chart to visualize the frequency of teams in a certain data frame: library(ggplot2)ĭf <- data. make two vectors of equal length x <- 1:50 y <- 51:100 plot(x, y) As you can see, it makes a simple plot of our data, using points as the default. One vector gives the x-value, and another gives the y-value. The following examples show how to create each of these plots in R. The commands are:CIRCx y rPlot a circle of radius r centered at (x, y)STORencurvedegreex 0 y 0 w 0x 1 y 1 w 1x 2 y 2 w 2.x n y n w nStore the control. The simplest way of plotting in R is by plotting two vectors of equal length. Three plots that are commonly used to visualize this type of data include: “high school”, “Bachelor’s degree”, “Master’s degree”) Smoking status (“smoker”, “non-smoker”).In statistics, categorical data represents data that can take on names or labels.
