Reputation: 3108
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?Upvotes: 0
Views: 207
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()
Upvotes: 1