I have created histogram and a line graph whose y-axis values are different as shown.
I want to have the two graphs in one plot.
I have created histogram and a line graph whose y-axis values are different as shown.
I want to have the two graphs in one plot.
This is a solution with basic plot:
set.seed(16011991)
x <- rnorm(100)
dots <- data.frame(c(-3,-2,-1,0,1,2,3),c(10,20,30,40,30,20,10))
hist(x)
lines(dots, col = "blue", lwd = 2)
Or ggplot:
set.seed(16011991)
x <- data.frame(norm = rnorm(100))
dots <- data.frame(x=seq(-3,3,0.05), y=log(1:length(seq(-3,3,0.05))))
ggplot(data = x, aes(x=norm, color='red')) +
geom_histogram(bins = 30, fill="white", show.legend = FALSE, size=1.1) +
geom_line(data = dots, aes(x=x,y=y), color= 'blue', size=1.1) +
labs(title= 'My histogram', x = 'N(0,1)', y='Count') +
theme_stata()
in ggplot you can scale the axes if you need to do this to make your graph