Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use R language to realize data Visualization drawing bar chart Bar Chart

Shulou Source: shulou.com Published: 2022-06-01 12:51:34 10月04日 Update

This article mainly shows you "how to use R language to achieve data visualization drawing bar chart bar chart", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use R language to achieve data visualization drawing bar chart bar chart" this article.

Suppose Xiao Xian is going to help a bookstore graphically show the most popular ones in 2018.

Bibliography, the data is shown below.

The bar chart looks good, but it is different from what Xiao Xian imagined. It is clear that my data are arranged according to sales volume from high to low, why are they drawn in alphabetical order?

After using the function reorder (), which sorts factors, it looks like the following figure, which is still different from what you imagined.

After searching the tutorials on the Internet for a long time, we did not find a simple way to sort the factors in descending order, so Xiao Xian boldly added a minus sign in front of the sorting vector parameters, but did not report a successful error. Unexpected surprise (sometimes bold attempts will also have surprises, oh, to find tutorials online, you have to understand other people's code first, and sometimes you find that reading for a long time does not help you).

The specific drawing process is as follows.

Step1. Preparation of drawing data

First of all, you should adjust the data you want to draw into a format that can be recognized by the R language and save it in excel to csv format.

Step2. Reading data of drawing data

Tags: Title data drawing sales bar language fairy sort visualization content classmate factor article help surprise code tutorial format or color Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Shulou Information macOS Huawei Docker