Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to create this type of plot by 'ggplot2'

[enter image description here][1]

[1]: https://i.stack.imgur.com/IgLOC.png – this is what i want to draw

[2]: https://i.stack.imgur.com/S2YfL.png – this is data of this plot

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Not a complete solution, but the essence.

library(tidyverse)
library(ggplot2)

df <- tibble(
  type = c("barley",
           "maize",
           "sunlower oil",
           "wheat"),
  ukraine = c(0.974, 0.1643, 0.4221, 0.0891),
  russia = c(0.095, 0.0160, 0.2140, 0.1420)
)

# A tibble: 4 x 3
  type         ukraine russia
  <chr>          <dbl>  <dbl>
1 barley        0.974   0.095
2 maize         0.164   0.016
3 sunlower oil  0.422   0.214
4 wheat         0.0891  0.142

df %>%  
  gather(-type, key = "country", value = "value") %>%  
  ggplot() + 
  aes(x = type, y = value, fill = country) + 
  geom_col() + 
  coord_flip() 

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading