how to plot in R by keeping the same order as in the given input CSV file
0
0
Entering edit mode
2.2 years ago

Hello, community,

I am using R programming ggplot2 to get this bubble plot,

library(reader)

data <- read.csv("C:\\Users\\user\\Documents\\class.csv", header=TRUE,sep=",", stringsAsFact=FALSE)

sizeRange <- c(0,20)
library(ggrepel)
library(ggplot2)

ggplot(data, aes(x=0,y=Class,label=Class)) + 
  geom_text_repel(nudge_x=-0.5,size=0.2,show.legend = F)+
  geom_point(aes(size = Total),colour="green",stroke=2,alpha = 0.5)+ 
  scale_size(range = sizeRange)+ 
  theme_bw() + 
          theme(panel.border = element_blank(), 
                panel.grid.major = element_blank(),
                panel.grid.minor = element_blank(), 
                axis.line = element_line(colour = "white"))

I have given CSV file as input but by default, it's plotting the data as Z-A. I want to plot according to the order I have in my CSV file.

Please suggest how that can be done ?

plot: enter image description here

input data :

Class Total

Acidobacteriia 131

Actinomycetia 24266

Armatimonadia 2

Chthonomonadetes 62

Bacteroidia 6822

Flavobacteriia 3235

Bacteroidetes-NA 0

Chloroflexia 77

Dehalococcoidia 63

Thermomicrobia 18

Cyano-NA-1 0

Cyano-NA-2 0

Deinococci 289

Bacilli 61290

Planctomycetia 292

Acidithiobacillia 110

Alphaproteobacteria 14495

Betaproteobacteria 14472

Deltaproteobacteria 1278

Epsilonproteobacteria 7123

Gammaproteobacteria 110632

Hydrogenophilalia 18

Oligoflexia 96

Spirochaetia 2019

Synergistia 103

Verrucomicrobiae 509

Thermoprotei 339

Halobacteria 550

Methanobacteria 480

Methanomicrobia 528

Thermococci 103

Nitrososphaeria 34

Thaumarchaeota-NA 0

bubble chart ggplot2 R • 880 views
ADD COMMENT
0
Entering edit mode

Follow @ rpolicastro 's post in how to plot in R using ggplot2 in a given order or try y=fct_inorder(Class) in ggplot

ADD REPLY

Login before adding your answer.

Traffic: 2455 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6