How to write bar chart code in R language?

In R language, you can use the barplot() function to create a bar chart. Here is a simple example code for plotting a basic bar chart:

# 创建一个数据向量
data <- c(10, 20, 30, 40, 50)

# 绘制柱状图
barplot(data, main="Simple Bar Plot", xlab="Categories", ylab="Values")

In this example, data is a data vector containing 5 values, which will be plotted as a bar graph. The main parameter is used to set the title of the bar graph, while the xlab and ylab parameters are used to set the labels for the X and Y axes.

You can also pass more parameters to the barplot() function to customize the appearance of the bar chart. For more detailed information, you can refer to R’s official documentation or use ?barplot to access the help documentation.

Leave a Reply 0

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