2

I've this data :

# A tibble: 19 x 8
   country               Prop_A            Prop_B         Prop_C              Prop_D            Prop_E            Prop_F         Prop_G
   <fct>                 <dbl>           <dbl>            <dbl>               <dbl>             <dbl>              <dbl>          <dbl>
 1 Austria               1                   1            0.912               0.912             0.518             0.999          0.567 
 2 Belgium               1                   1            0.821               1                 0.687             0.0990         0.925 
 3 Denmark              NA                  NA           NA                  NA                NA                NA             NA     
 4 France                0.750               1            0.361               0.345             0                 0.0658         0.563 
 5 Germany               0.928               1            0.674               0.783             0.128             0.635          0.0828
 6 Greece                0                   1            0                   0                 0                 1              0     
 7 Hungary               0.812               1            0.812               0.812             0                 0.375          0.188 
 8 Israel                1                   1            1                   0.755             0.450             0.241          0.292 
 9 Italy                 0.962               1            0.881               0.516             0.533             0              0.0230
10 Latvia                0                   1            1                   0                 0                 0              0     
11 Lithuania             0.507               1            1                   0.507             0                 0              0     
12 Malta                 1                   1            1                   1                 0                 1              0     
13 Netherlands           0.818               1            1                   0.682             0.5               0.182          0.682 
14 Portugal              0.829               1            1                   0.829             0                 0.610          0.509 
15 Romania               1                   1            1                   1                 0                 0.273          1     
16 Spain                 1                   1            1                   0.787             0.215             0.191          0.653 
17 Sweden                0.792               1            0.792               0.167             0.375             0              0     
18 Switzerland           0.697               1            1                   0.547             0.126             0.724          0.210 
19 Turkey                1                   1            0.842               0.775             0.585             0.810          0.117 
> 

0.812 represent 81% for the proposal A in Hungary (7)

What I want is this kind of graphic :

Exemple

https://zupimages.net/viewer.php?id=20/13/ob6z.png

I want to have "81%" in the bubble , countries in rows and the different "props" in columns.

I've tried geom_tile, but doesn't work. I don't understand if my data are not well built, or if i just don't find the good command.

Thank for your help !

Aytan
  • 136
  • 1
  • 9
  • Hey - in future please embed your image directly. Hyperlinks can change and people might not be able to see your graphic. Also, show what you have tried so far. Why does geom_tile 'not work'? – Conor Neilson Mar 26 '20 at 20:45
  • Yes, i want do that originaly, but not enough points (need 10, and newly created account :/) – Aytan Mar 26 '20 at 20:57

1 Answers1

2

Here is one approach to making a bubble plot.

library(tidyverse)

df %>%
  mutate_at(vars(starts_with("Prop")), list(~. * 100)) %>%
  pivot_longer(cols = starts_with("Prop"), names_to = c("Prop", "Type"), names_sep = "_") %>%
  ggplot(aes(x = Type, y = country, size = value, label = value)) +
  geom_point(shape = 21, fill = "white") +
  geom_text(size = 3) +
  scale_size(range = c(5, 15), guide = F)

Plot

bubble plot

Ben
  • 28,684
  • 5
  • 23
  • 45
  • Thanks! The result is kind of what I want :) I've just difficulty to understand "the list (~. * 100)" I understand it's for transforming 0,812 in 81.2, but I don't understand the structure (What seems the tilde? Why a point? search help mutate_at in google doesn't help me :/ – Aytan Mar 26 '20 at 21:30
  • Also, i've problem in my dataset, the graphic have numbers with many decimals, like 21.5236569854 ... How can i round it ? Can we pass multiple command in mutate_at ? – Aytan Mar 26 '20 at 21:34
  • The `~.` notation in `tidyverse` is equivalent to an anonymous function and could be substituted with `function(x) x...` – Ben Mar 26 '20 at 22:05
  • You can round when converting to 100% if you want, try something like: `mutate_at(vars(starts_with("Prop")), list(function(x) round(x * 100, digits = 0)))` ... you can adjust `digits` for decimal places... – Ben Mar 26 '20 at 22:06