1

I am new to ggplotly and R and I am struggling on the simplest issue. I want to zoom in on my secondary axis so the data stand out. However simple math does not seem to be working.

Squaring and square rooting the data. Adjusting ylim

library(tidyr)
library(readxl)
library(ggplot2)
library(tidyverse)
library(plotly)
data = read_excel("./Input/VC_AV.xlsx")
data[,2:4] <- data[,2:4]/1000000
data[,5:7] <- data[,5:7]/100000
head(data)
data_clean = gather(data, "Scenario", "Value", -Time)
head(data_clean)
p <- data_clean  %>% 
  ggplot(aes(Time, y=Value, col=Scenario)) +
  geom_line(aes(linetype=Scenario)) +
  scale_y_continuous(sec.axis = sec_axis(~./scale, name = "Coastal Proximity Amenity Value (NZ$M)")) +
  labs(x="Time", y= ("Vulnerable Residential Capital(NZ$M)")) +
  theme_minimal() + 
  theme(legend.position="bottom") +
p
ggplotly(p)

I wish to zoom in on the secondary y-axis to show the differences in the dataset while maintaining the original left-hand y-axis.

enter image description here

Ashton
  • 27
  • 2
  • 2
    1) Please include a MRE: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example 2) You refer to squaring and quare rooting the data but I can't see that in the code. 3) Where is `scale` defined? 4) In ggplot, secondary axes are ornament and don't change where the data appears, so I'm not sure how adding one will help the data stand out. – Jon Spring Sep 22 '19 at 02:21
  • Thanks Jon. I will take your advice as its ornamental and just adjust the ylim. Strange that it is so easy to do in excel but not ggplot. – Ashton Sep 23 '19 at 05:54

0 Answers0