Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to draw a column chart in R language to make your ass face to the right?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

The main content of this article is to explain "how to draw a bar chart with R language to the right". Interested friends might as well take a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to draw a bar chart with R language to make your ass face right".

Image.png

Because there is more data in figure A, let's imitate figure B. the process is actually the same.

The two graphs on the left of image.png are histograms, superimposed error lines, and superimposed scatter plots. The rightmost graph can be plotted with a heat map to construct the data set of the column chart first.

This is the first time that the column chart of the leftmost butt to the right has been drawn. If you check it, it can be realized with the help of the scale_y_reverse () function.

Set.seed (1234)

X df1

Group to find the mean and standard deviation library (dplyr)

Df% >%

Reshape2::melt ()% >%

Group_by (variable)% >%

Summarise (mean_value=mean (value))

Sd_value=sd (value))-> df2

Column chart superposition error line and scatter chart ggplot () +

Geom_col (data=df2,aes (xylene variation)

Fill= "# 8babd3"

Color= "black") +

Geom_errorbar (data=df2,aes (x=variable)

Ymin=mean_value-sd_value

Ymax=mean_value+sd_value)

Width=0.2) +

Geom_jitter (data=df1,aes (xylene variation)

Width = 0.2 color = "grey")

Image.png 's next step is to adjust the axes so that the buttocks face right ggplot () +

Geom_col (data=df2,aes (xylene variation)

Fill= "# 8babd3"

Color= "black") +

Geom_errorbar (data=df2,aes (x=variable)

Ymin=mean_value-sd_value+0.001

Ymax=mean_value+sd_value)

Width=0.2) +

Geom_jitter (data=df1,aes (xylene variation)

Width = 0.2 color = "grey") +

# scale_y_continuous (expand = c (0jin0)) +

Theme_bw () +

Coord_flip () +

Scale_y_reverse (expand=c (0d0)

Position= "right") +

Labs (xtriple null)

The second bar chart of image.png also draws ggplot () + directly with this data.

Geom_col (data=df2,aes (xylene variation)

Fill= "# ffc080"

Color= "black") +

Geom_errorbar (data=df2,aes (x=variable)

Ymin=mean_value-sd_value+0.001

Ymax=mean_value+sd_value)

Width=0.2) +

Geom_jitter (data=df1,aes (xylene variation)

Width = 0.2 color = "grey") +

Scale_y_continuous (expand = c (0B0)

Position = "right") +

Theme_bw () +

Coord_flip () +

Labs (xresume null) +

Theme (axis.text.y = element_blank ()

Axis.ticks.y = element_blank ()

Image.png is followed by the construction of the rightmost heat map data df3 p

Ggsave (filename = "Rplot10.pdf"

P

Width = 10) height = 3)

The final result is as follows

At this point, I believe you have a deeper understanding of "how to draw a bar chart with R language to the right". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report