ggplot2 histogram prblem

library(ggplot2)

year <- c(20144, 20144, 20151, 20151, 20152, 20152,
20153, 20153, 20154, 20154, 20161, 20161,
20162, 20162, 20163, 20163, 20164, 20164,
20171, 20171, 20172, 20172, 20173, 20173)
per <- c(73.9, 51.4, 73.1, 50.5, 74.4, 52.4, 74.2, 52.4, 73.5, 51.9,
73, 50.9, 74.2, 52.6, 74.5, 52.7, 73.8, 52.2, 73.1, 51.5,
74.5, 53.2, 74.2, 53.1)
gen <- c("man","woman","man","woman","man","woman","man","woman",
"man","woman","man","woman","man","woman","man","woman",
"man","woman","man","woman","man","woman","man","woman")

eco <- data.frame(year, per, gen)
eco

ggplot(eco, aes(x=per,fill = gen, color = year))+
geom_histogram(binwidth = 0.1, position = "dodge")

I want to customize the y-axis in this coding. I want to know if that is possible. If that doesn't work, I would like to express three things here: year, per, and gen. This is so difficult that I write a question. I would really appreciate your reply.

Can you describe how you want to customize the axes? Here is one way to present the data.

library(ggplot2)
year <- c(20144, 20144, 20151, 20151, 20152, 20152,
          20153, 20153, 20154, 20154, 20161, 20161,
          20162, 20162, 20163, 20163, 20164, 20164,
          20171, 20171, 20172, 20172, 20173, 20173)
per <- c(73.9, 51.4, 73.1, 50.5, 74.4, 52.4, 74.2, 52.4, 73.5, 51.9,
         73, 50.9, 74.2, 52.6, 74.5, 52.7, 73.8, 52.2, 73.1, 51.5,
         74.5, 53.2, 74.2, 53.1)
gen <- c("man","woman","man","woman","man","woman","man","woman",
         "man","woman","man","woman","man","woman","man","woman",
         "man","woman","man","woman","man","woman","man","woman")

eco <- data.frame(year, per, gen)
eco
#>     year  per   gen
#> 1  20144 73.9   man
#> 2  20144 51.4 woman
#> 3  20151 73.1   man
#> 4  20151 50.5 woman
#> 5  20152 74.4   man
#> 6  20152 52.4 woman
#> 7  20153 74.2   man
#> 8  20153 52.4 woman
#> 9  20154 73.5   man
#> 10 20154 51.9 woman
#> 11 20161 73.0   man
#> 12 20161 50.9 woman
#> 13 20162 74.2   man
#> 14 20162 52.6 woman
#> 15 20163 74.5   man
#> 16 20163 52.7 woman
#> 17 20164 73.8   man
#> 18 20164 52.2 woman
#> 19 20171 73.1   man
#> 20 20171 51.5 woman
#> 21 20172 74.5   man
#> 22 20172 53.2 woman
#> 23 20173 74.2   man
#> 24 20173 53.1 woman

ggplot(eco, aes(x = year, y=per,fill = gen))+
  geom_col( position = "dodge") +
  scale_x_continuous(breaks = c(20150, 20160, 20170),
                     labels = c("2015", "2016", "2017"))

Created on 2020-06-21 by the reprex package (v0.3.0)

Thanks a lot ! i spend all day long to solve this prblem...thank you!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.