Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Download R https://mirror.niser.ac.in/cran/bin/windows/base/R-4.5.0-win.exe
- #Simple Bar Chart
- # Create the data for the chart
- A <- c(17, 32, 8, 53, 1)
- # Plot the bar chart
- barplot(A, xlab = "X-axis", ylab = "Y-axis", main ="Bar-Chart")
- #############################################################################
- #Horizontal Bar Chart
- # Create the data for the chart
- A <- c(17, 32, 8, 53, 1)
- # Plot the bar chart
- barplot(A, horiz = TRUE, xlab = "X-axis",
- ylab = "Y-axis", main ="Bar-Chart")
- #############################################################################
- #Adding Color and Title
- # Create the data for the chart
- A <- c(17, 2, 8, 13, 1, 22)
- B <- c("Jan", "feb", "Mar", "Apr", "May", "Jun")
- # Plot the bar chart
- barplot(A, names.arg = B, xlab ="Month",
- ylab ="Articles", col ="green",
- main ="GeeksforGeeks-Article chart")
- #############################################################################
- #Creating Stacked Bar Chart
- colors = c("green", "orange", "brown")
- months <- c("Mar", "Apr", "May", "Jun", "Jul")
- regions <- c("East", "West", "North")
- # Create the matrix of the values.
- Values <- matrix(c(2, 9, 3, 11, 9, 4, 8, 7, 3, 12, 5, 2, 8, 10, 11),
- nrow = 3, ncol = 5, byrow = TRUE)
- # Create the bar chart
- barplot(Values, main = "Total Revenue", names.arg = months,
- xlab = "Month", ylab = "Revenue",
- col = colors, beside = TRUE)
- # Add the legend to the chart
- legend("topleft", regions, cex = 0.7, fill = colors)
- #Example 2
- colors = c("green", "orange", "brown")
- months <- c("Mar", "Apr", "May", "Jun", "Jul")
- regions <- c("East", "West", "North")
- # Create the matrix of the values.
- Values <- matrix(c(2, 9, 3, 11, 9, 4, 8, 7, 3, 12, 5, 2, 8, 10, 11),
- nrow = 3, ncol = 5, byrow = TRUE)
- # Create the bar chart
- barplot(Values, main = "Total Revenue", names.arg = months,xlab = "Month", ylab = "Revenue", col = colors)
- # Add the legend to the chart
- legend("topleft", regions, cex = 0.7, fill = colors)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement