Home > database >  ggplot not ploting histogram
ggplot not ploting histogram

Time:05-12

I'm trying to plot a mirrored histogram based on the following data (snippet):

enter image description here

Where on the x-axis x goes from 0 to 150 (range of both variables Ilhavo and VNTelha-Maia) in subgroups of 10 and on the "dual" y-axis is the number of times (horas) each number under Ilhavo and VNTelha-Maia are repeated.

Basically I want to get something like this: enter image description here

However, no matter what I do I can't seem to create it.

Here's what I have tried:

library(ggplot2)
library(readxl)

p <- ggplot(QualidadeARO3, aes(x=Ilhavo) )  
  geom_histogram( breaks=seq(0, 150, by=10), aes(x = Ilhavo , y = ..horas..), fill="#69b3a2" )  
  geom_label( aes(x=Ilhavo, y=horas, label="Ilhavo"), color="#69b3a2")  
  geom_histogram(breaks=seq(0, 150, by=10), aes(x = VNTelha-Maia, y = -..horas..), fill= "#404080")  
  geom_label( aes(x=VNTelha-Maia, y=horas, label="VN Telha"), color="#404080")  
 
  xlab("microgramas/metro cúbico")

But nothing happens. Any help?

CodePudding user response:

Something like this:

ggplot(df, aes(x=x) )  
  geom_histogram(breaks=seq(0, 150, by=10), aes(x = Ilhavo, y = ..density..), fill="#69b3a2" )  
  geom_label( aes(x=100, y=0.05, label="Ilhavo"), color="#69b3a2")  
  geom_histogram(breaks=seq(0, 150, by=10), aes(x = VNTelha_Maia, y = -..density..), fill= "#404080")  
  geom_label( aes(x=100, y=-0.05, label="VNTelha_Maia"), color="#404080")  
  theme_bw()

enter image description here

  • Related