dataset <- read_xlsx("bar.xlsx")
db <- (dataset)
db1 = as.data.frame(db[,1:2])
db2 = db[,c(1,3)]
db3 = db[,c(1,4)]
ylim.prim <- c(0,4000 ) # in this example, precipitation
ylim.sec <- c(0, 600) # in this example, temperature
b <- diff(ylim.prim)/diff(ylim.sec)
a <- b*(ylim.prim[1] - ylim.sec[1])
db1 = as.data.frame(db1)
dat.m <- melt(db1, id='Elevation')
dat.m1 <- melt(db2, id='Elevation')
dat.m2 <- melt(db3, id='Elevation')
plot1 <-ggplot() +
geom_bar(data = dat.m, aes(x = dat.m$Elevation, y = dat.m$value,fill = variable), stat = 'identity', position = 'dodge')+
geom_line(data= dat.m1, aes(x= dat.m1$Elevation,y=a+ dat.m1$value*b ),color="black",size=1 )+
scale_y_continuous("Area (km2)",breaks = c(0,500,1000,1500,2000,2500,3000,3500,4000), labels = c(0,500,1000,1500,2000,2500,3000,3500,4000),
sec.axis = sec_axis(~ (. - a)/b,breaks = c(0,50,100,150,200,250,300,350,400,450,500,550,600), labels = c(0,50,100,150,200,250,300,350,400,450,500,550,600), name = "Glacerized Area (Km2)"))+
labs(x="Elevation (m)", title="Gilgit Hysometric Curve")+ theme_bw()+
scale_x_continuous(limits = c(0,8000),breaks = c(0,500,1000,1500,2000,2500,3000,3500,4000,4500,5000,5500,6000,6500,7000,7500,8000), labels = c(0,500,1000,1500,2000,2500,3000,3500,4000,4500,5000,5500,6000,6500,7000,7500,8000))+
theme(axis.title.x = element_text(color = "black", size = 12, face = "bold"),axis.title.y = element_text(color = "black", size = 10, face = "bold"))+
theme(axis.text.x = element_text(face="bold", color="black",size=10),
axis.text.y = element_text(face="bold", color="black", size=10))
#figure <- ggarrange(plot1,plot2,plot3,plot4,plot5,plot6,
#labels = c("Astore", "Gilgit","Hunza","Indus Down Stream","Shigar","Shyok",font.label = 4),
#ncol = 2, nrow = 3)
figure <-plot1+ ggsave("hypsometric curve.png",width=10, height= 8,dpi=300)
Dear All, I am trying to develop hypsometric curve using ggplot. As you see in the attachment excel file as well as png picture. I developed the area elevation and glacerized curve but I did not understand how to mean monthly temperature on it.
Kindly guide me how I can plot mean monthly temperature on secondry horizontal axis.
bar.pdf (62.4 KB)