- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create bar plot with positive and negative values in R?
To create bar plot with positive and negative values, we can make use of ggplot function.
For example, if we have a data frame called df that contains a categorical column say C and a numerical column Num which has some positive and some negative values then the bar plot for this data can be created by using the below command −
Following snippet creates a sample data frame −
Category<-c("Egypt","Sudan","Turkey","Indonesia") Response_Score<-c(10,-2,4,-5) df<-data.frame(Category,Response_Score) df
The following dataframe is created −
Category Response_Score 1 Egypt 10 2 Sudan -2 3 Turkey 4 4 Indonesia -5
To load ggplot2 package and create bar chart for data stored in df, add the following code to the above snippet −
If you execute all the above given snippets as a single program, it generates the following output −
- How to create plotly bar chart with negative values in R?
- How to create bar plot with log values using ggplot2 in R?
- How to create a bar plot with bars for missing values in R?
- How to convert negative values in an R data frame to positive values?
- How to create empty bar plot in base R?
- How to create a bar plot with ggplot2 using stat_summary in R?
- Java Program to convert positive int to negative and negative to positive
- How to create transparent bar plot using ggplot2 in R?
- How to create a bar plot using ggplot2 with one bar having black border in R?
- How to create bar plot with gradient colors using ggplot2 in R?\n
- How to find the groupwise number of positive and negative values in an R data frame?
- How to create the stacked bar plot using ggplot2 in R with labels on the plot?
- Positive Testing and Negative Testing with Examples
- How to create a stacked bar plot with vertical bars in R using ggplot2?