Home > Blockchain >  Reducing the bubble size in ggplot2 geom point
Reducing the bubble size in ggplot2 geom point

Time:10-24

This my intended visualizationfig

But I'm getting something like this I'm not able to fix the bubble size as well as the asociateed color the way its shown in first figure

this image i get

My code and the data used small subset is this

My data

dput(aaa)
structure(list(term_ID = structure(1:10, .Label = c("GO:0000902", 
"GO:0000904", "GO:0001501", "GO:0001505", "GO:0001934", "GO:0001944", 
"GO:0002250", "GO:0002252", "GO:0003002", "GO:0003012", "GO:0003013", 
"GO:0006836", "GO:0006897", "GO:0006909", "GO:0006910", "GO:0006935", 
"GO:0006941", "GO:0006954", "GO:0006958", "GO:0006959", "GO:0007160", 
"GO:0007167", "GO:0007169", "GO:0007389", "GO:0007599", "GO:0008015", 
"GO:0008037", "GO:0009611", "GO:0009617", "GO:0010324", "GO:0030048", 
"GO:0030198", "GO:0030574", "GO:0031175", "GO:0031344", "GO:0032409", 
"GO:0032940", "GO:0032963", "GO:0032989", "GO:0034330", "GO:0034762", 
"GO:0034765", "GO:0035150", "GO:0035239", "GO:0035637", "GO:0035987", 
"GO:0040011", "GO:0042060", "GO:0043062", "GO:0043269", "GO:0043408", 
"GO:0043410", "GO:0044057", "GO:0045229", "GO:0046903", "GO:0048598", 
"GO:0048705", "GO:0050767", "GO:0050808", "GO:0050817", "GO:0050865", 
"GO:0050871", "GO:0050878", "GO:0050900", "GO:0051282", "GO:0051960", 
"GO:0060284", "GO:0060306", "GO:0070252", "GO:0071345", "GO:0086001", 
"GO:0098609", "GO:0098900", "GO:0098901", "GO:0099003", "GO:0099504", 
"GO:0099537", "GO:0120035", "GO:0140352", "GO:1903115", "GO:1903522"
), class = "factor"), description = structure(c(7L, 8L, 71L, 
60L, 44L, 79L, 3L, 30L, 45L, 36L), .Label = c("actin filament-based movement", 
"actin-mediated cell contraction", "adaptive immune response", 
"blood circulation", "cardiac muscle cell action potential", 
"cell junction organization", "cell morphogenesis", "cell morphogenesis involved in differentiation", 
"cell recognition", "cell-cell adhesion", "cell-matrix adhesion", 
"cellular component morphogenesis", "cellular response to cytokine stimulus", 
"chemotaxis", "circulatory system process", "coagulation", "collagen catabolic process", 
"collagen metabolic process", "complement activation, classical pathway", 
"embryonic morphogenesis", "endocytosis", "endodermal cell differentiation", 
"enzyme-linked receptor protein signaling pathway", "export from cell", 
"external encapsulating structure organization", "extracellular matrix organization", 
"extracellular structure organization", "hemostasis", "humoral immune response", 
"immune effector process", "inflammatory response", "leukocyte migration", 
"locomotion", "membrane invagination", "multicellular organismal signaling", 
"muscle system process", "neuron projection development", "neurotransmitter transport", 
"pattern specification process", "phagocytosis", "phagocytosis, recognition", 
"positive regulation of B cell activation", "positive regulation of MAPK cascade", 
"positive regulation of protein phosphorylation", "regionalization", 
"regulation of actin filament-based movement", "regulation of action potential", 
"regulation of blood circulation", "regulation of body fluid levels", 
"regulation of cardiac muscle cell action potential", "regulation of cell activation", 
"regulation of cell development", "regulation of cell projection organization", 
"regulation of ion transmembrane transport", "regulation of ion transport", 
"regulation of MAPK cascade", "regulation of membrane repolarization", 
"regulation of nervous system development", "regulation of neurogenesis", 
"regulation of neurotransmitter levels", "regulation of plasma membrane bounded cell projection organization", 
"regulation of sequestering of calcium ion", "regulation of system process", 
"regulation of transmembrane transport", "regulation of transporter activity", 
"regulation of tube size", "response to bacterium", "response to wounding", 
"secretion", "secretion by cell", "skeletal system development", 
"skeletal system morphogenesis", "striated muscle contraction", 
"synapse organization", "synaptic vesicle cycle", "trans-synaptic signaling", 
"transmembrane receptor protein tyrosine kinase signaling pathway", 
"tube morphogenesis", "vasculature development", "vesicle-mediated transport in synapse", 
"wound healing"), class = "factor"), frequency = c(3.90388708412681, 
3.0469362607819, 2.85650274448303, 1.22101489862216, 4.17833538702812, 
2.92371457376498, 3.67984765318696, 2.54284754116725, 1.89313319144169, 
1.57387700235241), plot_X = c(6.92244115457684, 6.72491915133615, 
5.75342433388847, -4.90486321695327, -4.34558231048815, 5.9436291821168, 
-0.331063511422281, -2.02986678951973, 6.27772046499967, 5.90846183785093
), plot_Y = c(-0.441477421046203, -0.357893626091624, -1.89830400195803, 
3.81175482612134, -4.96413463620965, -2.091036211506, -6.52348278338337, 
-6.97095859836097, -2.24397905128075, -3.82681903766349), log_size = c(2.84385542262316, 
2.73639650227664, 2.70842090013471, 2.34044411484012, 2.8733206018154, 
2.71850168886727, 2.81822589361396, 2.65801139665711, 2.53019969820308, 
2.45024910831936), value = c(-9.8138097104, -9.3084572558, -7.983023664, 
-3.2017781871001, -6.0366705271, -8.4472753844, -21.0694271164, 
-9.0630211246, -3.94894435910093, -1.87037981820001), uniqueness = c(0.857575132627072, 
0.816670053918386, 0.841547228295729, 0.886390429364808, 0.807466832663465, 
0.830691169997519, 0.839912555176311, 0.892202047678151, 0.847227910985189, 
0.868600113222042), dispensability = c(0, 0.69190667, 0.44917845, 
0.379708, 0.14243226, 0.45070828, 0, 0.57560152, 0.40006623, 
0.55626845)), row.names = c(NA, 10L), class = "data.frame")

The code used, I tried to multiply a decimal into the size argument input which is log_size but still I was not able to make it proportional as well as the color

p1 <- ggplot( data = aaa );
p1 <- p1   geom_point( aes( plot_X, plot_Y, colour = value, size = log_size), alpha = I(0.6) );
p1 <- p1   scale_colour_gradientn( colours = c("blue", "green", "yellow", "red"), limits = c( min(one.data$value), 0) );
p1 <- p1   geom_point( aes(plot_X, plot_Y, size = log_size), shape = 21, fill = "transparent", colour = I (alpha ("black", 0.6) ));
p1 <- p1   scale_size( range=c(5, 30))   theme_bw(); #   scale_fill_gradientn(colours = heat_hcl(7), limits = c(-300, 0) );
ex <- one.data [ one.data$dispensability < 0.15, ];
p1 <- p1   geom_text( data = ex, aes(plot_X, plot_Y, label = description), colour = I(alpha("black", 0.85)), size = 3 );
p1 <- p1   labs (y = "semantic space x", x = "semantic space y");
p1 <- p1   theme(legend.key = element_blank()) ;
one.x_range = max(one.data$plot_X) - min(one.data$plot_X);
one.y_range = max(one.data$plot_Y) - min(one.data$plot_Y);
p1 <- p1   xlim(min(one.data$plot_X)-one.x_range/10,max(one.data$plot_X) one.x_range/10);
p1 <- p1   ylim(min(one.data$plot_Y)-one.y_range/10,max(one.data$plot_Y) one.y_range/10);


# --------------------------------------------------------------------------
# Output the plot to screen

p1;

Any suggestion or help would be really appreciated

CodePudding user response:

Is this what you are looking to do with the size legend? It's not clear what you want to do differently with the color. Clearly you have different values you are mapping so you have different results.

ggplot(data = aaa ) 
    geom_point( aes( plot_X, plot_Y, colour = value, size = log_size), alpha = I(0.6) ) 
    scale_colour_gradientn( colours = c("blue", "green", "yellow", "red"), limits = c( min(aaa$value), 0) ) 
    geom_point( aes(plot_X, plot_Y, size = log_size), shape = 21, fill = "transparent", colour = I (alpha ("black", 0.6) )) 
    scale_size_continuous(breaks = seq(range(aaa$log_size)[1], range(aaa$log_size)[2], length.out = 2))

enter image description here

CodePudding user response:

I think this is a bit closer to the original. Note I changed the fields being graphed as the values you had selected didn't line up with the example.

library(ggplot2)
library(ggrepel)
library(ggthemes)

ex <- aaa[aaa$dispensability < 0.15, ]

ggplot(data = aaa ) 
    geom_point( aes( plot_X, plot_Y, colour = frequency, size = -value), alpha = I(0.6) ) 
    scale_colour_gradientn(colours = c("purple", "violet", "yellow", "orange", "red"), 
                           limits = c(ceiling(min(aaa$frequency)), ceiling(max(aaa$frequency)))) 
    scale_size_continuous(breaks = seq(from = 5, to = round(max(-aaa$value),-1), length.out = 2 )) 
    geom_text_repel(data = ex, aes(plot_X, plot_Y, label = description), colour = I(alpha("black", 0.85)), size = 3 ,
                    min.segment.length = 0, nudge_y = 0.5) 
    xlim(-ceiling(max(abs(min(aaa$plot_X)), abs(max(aaa$plot_X)))), ceiling(max(abs(min(aaa$plot_X)), abs(max(aaa$plot_X)))))  
    ylim(-ceiling(max(abs(min(aaa$plot_Y)), abs(max(aaa$plot_Y)))), ceiling(max(abs(min(aaa$plot_Y)), abs(max(aaa$plot_Y)))))  
    labs(x = "semantic space y", y = "semantic space x", color = "-log10 adj.pvalue", size = "count")  
    theme_few()

enter image description here

  • Related