LDT
LDT

Reputation: 3108

Plot upside down geom_col() plot with ggplot2 in R

I am not sure what I am doing wrong. I want to plot on the one y-axis the y-values of the diamond dataset and on the negative y-axis, the z-values of the diamond dataset.

When I try this, I get very absurd values since the max of y and z are far smaller.

library(ggplot2)
  
ggplot(data = diamonds) + 
  geom_col(aes(x = x,y = y), color="#edae49") + 
  geom_col(aes(x = x,y = -z), color="#66a182") +
  theme_bw()


max(diamonds$y)
#> [1] 58.9
max(diamonds$z)
#> [1] 31.8

Created on 2022-08-22 with reprex v2.0.2

any idea what I am doing so wrong?
**I want to see bars from min to max in each position.**

Upvotes: 0

Views: 207

Answers (1)

amanwebb
amanwebb

Reputation: 380

library(ggplot2)
  
ggplot(data = diamonds) + 
  geom_col(aes(x = x, y = y), color="#edae49", position = 'identity') + 
  geom_col(aes(x = x, y = -z), color="#66a182", position = 'identity') +
  theme_bw()

Positive/Negative geom_col

Upvotes: 1

Related Questions