![]() However, the same thing could be easily done with other plotting libraries such as gplots. That would be very complicated to achieve here. However, suppose we also wanted to plot max and min sales for each product line as markers above and below the mean bars. For example, in the above bar chart, we could have plotted mean revenue values instead of totals. The base graphics library provides only basic features for plotting charts. Alternatively, you can also specify the hex codes for the colors. To supply explicit colors, you would pass the col argument as col = c("Red", "Green", "Blue". In the following example, we extend our bar plot by painting the bars with rainbow colors: > barplot(sales_by_productline, col=rainbow(5), main="Sales by ProductLine", xlab="ProductLine",ylab="$") Alternatively you can explicitly supply a vector containing color codes. Similarly the rainbow function generates a vector of rainbow colors. R has some inbuilt functions to generate vectors of colors, for example, the gray function generates a vector of grays. ![]() The col argument is basically a vector of colors. We can add different colors to the bars in the bar plot by adding the col argument. The resulting bar plot is displayed below: > barplot(sales_by_productline, main="Sales by ProductLine", xlab="ProductLine",ylab="$") We can enhance the chart by adding a title and axis labels. The above function call will create the bar chart. The first step is to group the Total Sales by ProductLine using the tapply() function as shown below: > sales_by_productline barplot(sales_by_productline) We can use this data to create a bar chart which plots the total or average sales on y-axis as bars and the x-axis as one of these factors that we are interested in such as ProductLine. Let's take our Product Sales data where we have the Revenue and Gross Margin for each order along with various attributes such as ProductLine, RetailerType, OrderMethod etc. It presents grouped data using rectangular bars whose lengths are proportional to the values that they represent. ![]() A Bar Plot or Bar Graph is primarily used to compare values. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |