Skip to content

Data Science Tutorials

  • Home
  • R
  • Statistics
  • Course
  • Machine Learning
  • Guest Blog
  • Contact
  • About Us
  • Toggle search form
  • Applications of Data Science in Education
    Applications of Data Science in Education Machine Learning
  • Count Observations by Group in R
    Count Observations by Group in R R
  • Best online course for R programming
    Best online course for R programming Course
  • How to Rank by Group in R?
    How to Rank by Group in R? R
  • How to create contingency tables in R
    How to create contingency tables in R? R
  • How to compare the performance of different algorithms in R
    How to compare the performance of different algorithms in R? R
  • gganatogram Plot in R
    How to create Anatogram plot in R R
  • How to Find Optimal Clusters in R, K-means clustering is one of the most widely used clustering techniques in machine learning.
    How to Find Optimal Clusters in R? R
Rounded corner bar plot in R

How to make a rounded corner bar plot in R?

Posted on May 14May 14 By Jim No Comments on How to make a rounded corner bar plot in R?
Tweet
Share
Share
Pin

Rounded corner bar plot in R, we’ll show you how to use the ggchicklet package in the R programming language to make a ggplot2 bar chart with rounded bars.

The ggchicklet Package: An Overview

Bob Rudis’ ggchicklet package includes utilities for creating rounded rectangle segmented column charts (often known as “chicklets”).

Let’s dive into the topic.

Example 1: Barplot with Round Corners in R

We’ll teach you how to make rounded-corner barplots in R using the ggplot2 and ggchicklet package.

We must first create some data for this example.

df <- data.frame(value = 1:5,
                    group = LETTERS[1:5])
df
  value group
1     1     A
2     2     B
3     3     C
4     4     D
5     5     E

We constructed a data frame with a numeric and a character column by running the prior code.

The ggplot2 package must then be loaded.

How to Use the Multinomial Distribution in R?

install.packages("ggplot2")                 
library("ggplot2")                               

We can now use the geom col method to create a conventional ggplot2 barplot, as illustrated below.

ggplot(data1, aes(group, value)) +      
geom_col()

 The barchart depicted in Figure 1 was constructed after executing the previous R programming code.

The corners of the bars are not yet rounded, as you can see.

We must also install and load the ggchicklet package in order to produce a bar graph with round corners.

install.packages("ggchicklet", repos = "https://cinc.rud.is")
library("ggchicklet")

We can now construct a barplot with round corners using the ggchicklet package’s geom chicklet function.

The radius argument in the geom chicklet function can be used to indicate how round the corners should be.

Rejection Region in Hypothesis Testing

ggplot(data1, aes(group, value)) + 
geom_chicklet(radius = grid::unit(3, "mm"))

As you can see, we’ve made another ggplot2 barplot, but this time we’ve rounded the edges of the bars.

Example 2: Stacked ggplot2 Barplot with Round Corners

When developing stacked barplots, we think rounded corners seem particularly petty.

To demonstrate this, we must first construct a new data set.

df2 <- data.frame(value = 1:16,
                   group = rep(LETTERS[1:4], each = 4),
                   sub = letters[1:4])
df2
   value group sub
1     1     A   a
2     2     A   b
3     3     A   c
4     4     A   d
5     5     B   a
6     6     B   b

The outcome of the previous code is shown above: A data frame with group and subgroup columns, as well as a values column.

Best Data Science YouTube Tutorials Free to Learn

The geom chicklet function can then be used to create a stacked barplot of these data. Note that the fill parameter is also specified within the aesthetics of our plot.

ggplot(df2, aes(group, value, fill = sub)) +  
geom_chicklet(radius = grid::unit(3, "mm"))

Check your inbox or spam folder to confirm your subscription.

Tweet
Share
Share
Pin
R

Post navigation

Previous Post: How to perform the Kruskal-Wallis test in R?
Next Post: Best Books to Learn R Programming

Related Posts

  • Tips for Rearranging Columns in R
    Tips for Rearranging Columns in R R
  • How to Get a Job as a Data Engineer
    How to Get a Job as a Data Engineer? R
  • How to add columns to a data frame in R
    How to add columns to a data frame in R R
  • How to perform MANOVA test in R
    How to perform the MANOVA test in R? R
  • Hypothesis Testing in R
    Hypothesis Testing in R R
  • Calculate the p-Value from Z-Score in R
    Calculate the p-Value from Z-Score in R R

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • About Us
  • Contact
  • Disclaimer
  • Guest Blog
  • Privacy Policy
  • YouTube
  • Twitter
  • Facebook
  • Top 7 Skills Required to Become a Data Scientist
  • Learn Hadoop for Data Science
  • How Do Online Criminals Acquire Sensitive Data
  • Top Reasons To Learn R in 2023
  • Linear Interpolation in R-approx

Check your inbox or spam folder to confirm your subscription.

 https://www.r-bloggers.com
  • How to Add a title to ggplot2 Plots in R
    How to Add a caption to ggplot2 Plots in R? R
  • Artificial Intelligence Examples
    Artificial Intelligence Examples-Quick View Course
  • How to Group and Summarize Data in R
    How to Group and Summarize Data in R R
  • How to put margins on tables or arrays in R?
    How to put margins on tables or arrays in R? R
  • How to perform TBATS Model in R
    How to perform TBATS Model in R R
  • Top 7 Skills Required to Become a Data Scientist
    Top 7 Skills Required to Become a Data Scientist Machine Learning
  • how to draw heatmap in r
    How to draw heatmap in r: Quick and Easy way R
  • Data Scientist in 2023
    How to Become a Data Scientist in 2023 Machine Learning

Copyright © 2023 Data Science Tutorials.

Powered by PressBook News WordPress theme