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 Bubble Chart in R language

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

Share

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

This article mainly explains "how to draw bubble charts with R language". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "how to draw bubble charts with R language" together.

The first step is to prepare the data.

Some of the data sets are as follows

image.png

4 columns in total

The first two columns are variables, the third column is correlation coefficients, and the fourth column is significant P values.

The variables in front need to be noted, because only the triangle is drawn, so the time to prepare the data is:

The total variables are 10 x1 's in the first column, followed by 9 x2 's, and then 8 x3 's.

Step 1 Tree reads data df%

mutate(label=case_when(

signi0.001&signi0.01&signi df1

And then there's the plot.

First up is the bubble diagram of the upper triangle.

library(ggplot2)

ggplot(data=df1,aes(x=var_x,y=var_y))+

geom_point(aes(size=value,color=value))+

scale_color_gradient(low = "#80fcfe",high = "#ff80fc",

breaks=seq(-1,1,0.2))+

scale_size_continuous(range = c(5,15))+

guides(size=F)

image.png

In this case, X10 is not in the right position, so set the level of the factor

df1$var_x df2

head(df2)

ggplot(data=df1,aes(x=var_x,y=var_y))+

geom_point(aes(size=value,color=value))+

scale_color_gradient(low = "#80fcfe",high = "#ff80fc",

breaks=seq(-1,1,0.2))+

scale_size_continuous(range = c(5,15))+

guides(size=F)+

theme_bw()+

geom_text(data=df2,aes(x=var_y,y=var_x,

label=paste0(value,label)))

image.png

Finally adjust the legend height

df1%>%

filter(var_x!= var_y) -> df2

head(df2)

ggplot(data=df1,aes(x=var_x,y=var_y))+

geom_point(aes(size=value,color=value))+

scale_color_gradient(low = "#80fcfe",high = "#ff80fc",

breaks=seq(-1,1,0.2))+

scale_size_continuous(range = c(5,15))+

guides(size=F)+

theme_bw()+

geom_text(data=df2,aes(x=var_y,y=var_x,

label=paste0(value,label)))+

theme(legend.key.height = unit(3.5,'cm'),

legend.justification = c(0,0),

legend.title = element_blank())

Thank you for reading, the above is "how to draw bubble diagram with R language" content, after the study of this article, I believe we have a deeper understanding of how to draw bubble diagram with R language, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

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