Home > Blockchain >  can not have consistent point size in geom_size (in ggplot)
can not have consistent point size in geom_size (in ggplot)

Time:02-11

I have two dataset and produce bubble chart with ggplot. when I want to scale the point size, they do not stay consistent. for example circle with count of 3 is bigger thant ciricle with count size of 3 in df_table1.

df_table1:

         Raw.data temporal.technique Counts
         LMSdata         clustering      3
         LMSdata                 PM      3
         LMSdata      visualization      3
     custLogData               stat      2
    learningProd               stat      2
    perfMeasures      visualization      2
      contextual         clustering      1
      contextual            network      1
      contextual         TextMining      1
     custLogData          otherPred      1

df_table2:

         Raw.data temporal.technique Counts
         LMSdata         clustering      15
         LMSdata      visualization      8
     custLogData               stat      7
    learningProd               stat      4
    perfMeasures      visualization      3
     contextual         clustering      1
     contextual            network      1

I tried this code but did not make point sizes consistent. using fix number like scale_size(range = c(1, 10) did not work either.

ggplot(df_table, aes(x=df_table[,1], y=df_table[,2], size = Counts))   
    geom_text(data=df_table,aes(x=df_table[,1], y=df_table[,2],label= Counts,size=1.5))  
    scale_size(range = c(1, max(df_table$Counts))) 

CodePudding user response:

Does this approach solve your problem?

library(tidyverse)

df_table1 <- read.table(text = "         Raw.data temporal.technique Counts
         LMSdata         clustering      3
         LMSdata                 PM      3
         LMSdata      visualization      3
     custLogData               stat      2
    learningProd               stat      2
    perfMeasures      visualization      2
      contextual         clustering      1
      contextual            network      1
      contextual         TextMining      1
     custLogData          otherPred      1", header = TRUE)

df_table2 <- read.table(text = "         Raw.data temporal.technique Counts
         LMSdata         clustering      15
         LMSdata      visualization      8
     custLogData               stat      7
    learningProd               stat      4
    perfMeasures      visualization      3
     contextual         clustering      1
     contextual            network      1", header = TRUE)

# Combine df_table1 and df_table2 to a single df
df_table <- map_df(.x = list("df_table1" = df_table1,
                             "df_table2" = df_table2),
                   .f = bind_rows,
                   .id = "src")

# Plot them side-by-side using `facet_wrap()`
ggplot(df_table, aes(x=Raw.data, y=temporal.technique, size = Counts))   
  geom_text(aes(label = Counts))   
  scale_size(range = c(1, 10))  
  facet_wrap(~src)

Created on 2022-02-08 by the reprex package (v2.0.1)

  • Related