Я пытаюсь нанести 2 линии на график. При простой прорисовке одной из линий это работает; однако, когда я использую «add_trace» для другой строки, он просто работает как обе строки, бегущие отдельно по оси x (вроде как y = 0). Я приложил код ниже:
# #Profit Dataframe
df5 <- data.frame(Account_Num,Account_Num_Spec,Account_Name,Billing_Num,Date,Tran_Type,Transaction_Amt2,Bar_Date, Bar_Month,Trannn)
df5_subset <- reactive({
n1 <- input$PYR
n2 <- input$PYT
if(n2 == "Combined"){
c5 <- subset(df5, Bar_Date == n1)
}
else{
c5 <- subset(df5, Bar_Date == n1 & Trannn == n2)
}
return(c5)
})
clarify <- reactive({
check <- input$PYT
if(check == "Combined"){
jan_dataB <- subset(df5_subset(), Bar_Month == 01, Tran_Type == "Bill")
feb_dataB <- subset(df5_subset(), Bar_Month == 02, Tran_Type == "Bill")
mar_dataB <- subset(df5_subset(), Bar_Month == 03, Tran_Type == "Bill")
apr_dataB <- subset(df5_subset(), Bar_Month == 04, Tran_Type == "Bill")
may_dataB <- subset(df5_subset(), Bar_Month == 05, Tran_Type == "Bill")
jun_dataB <- subset(df5_subset(), Bar_Month == 06, Tran_Type == "Bill")
jul_dataB <- subset(df5_subset(), Bar_Month == 07, Tran_Type == "Bill")
aug_dataB <- subset(df5_subset(), Bar_Month == 08, Tran_Type == "Bill")
sep_dataB <- subset(df5_subset(), Bar_Month == 09, Tran_Type == "Bill")
oct_dataB <- subset(df5_subset(), Bar_Month == 10, Tran_Type == "Bill")
nov_dataB <- subset(df5_subset(), Bar_Month == 11, Tran_Type == "Bill")
dec_dataB <- subset(df5_subset(), Bar_Month == 12, Tran_Type == "Bill")
jan_dataR <- subset(df5_subset(), Bar_Month == 01, Tran_Type == "Receipt")
feb_dataR <- subset(df5_subset(), Bar_Month == 02, Tran_Type == "Receipt")
mar_dataR <- subset(df5_subset(), Bar_Month == 03, Tran_Type == "Receipt")
apr_dataR <- subset(df5_subset(), Bar_Month == 04, Tran_Type == "Receipt")
may_dataR <- subset(df5_subset(), Bar_Month == 05, Tran_Type == "Receipt")
jun_dataR <- subset(df5_subset(), Bar_Month == 06, Tran_Type == "Receipt")
jul_dataR <- subset(df5_subset(), Bar_Month == 07, Tran_Type == "Receipt")
aug_dataR <- subset(df5_subset(), Bar_Month == 08, Tran_Type == "Receipt")
sep_dataR <- subset(df5_subset(), Bar_Month == 09, Tran_Type == "Receipt")
oct_dataR <- subset(df5_subset(), Bar_Month == 10, Tran_Type == "Receipt")
nov_dataR <- subset(df5_subset(), Bar_Month == 11, Tran_Type == "Receipt")
dec_dataR <- subset(df5_subset(), Bar_Month == 12, Tran_Type == "Receipt")
yloc1B <- sum(as.numeric(as.character(jan_dataB$Transaction_Amt2)))
yloc2B <- sum(as.numeric(as.character(feb_dataB$Transaction_Amt2)))
yloc3B <- sum(as.numeric(as.character(mar_dataB$Transaction_Amt2)))
yloc4B <- sum(as.numeric(as.character(apr_dataB$Transaction_Amt2)))
yloc5B <- sum(as.numeric(as.character(may_dataB$Transaction_Amt2)))
yloc6B <- sum(as.numeric(as.character(jun_dataB$Transaction_Amt2)))
yloc7B <- sum(as.numeric(as.character(jul_dataB$Transaction_Amt2)))
yloc8B <- sum(as.numeric(as.character(aug_dataB$Transaction_Amt2)))
yloc9B <- sum(as.numeric(as.character(sep_dataB$Transaction_Amt2)))
yloc10B <- sum(as.numeric(as.character(oct_dataB$Transaction_Amt2)))
yloc11B <- sum(as.numeric(as.character(nov_dataB$Transaction_Amt2)))
yloc12B <- sum(as.numeric(as.character(dec_dataB$Transaction_Amt2)))
yloc1R <- sum(as.numeric(as.character(jan_dataR$Transaction_Amt2)))
yloc2R <- sum(as.numeric(as.character(feb_dataR$Transaction_Amt2)))
yloc3R <- sum(as.numeric(as.character(mar_dataR$Transaction_Amt2)))
yloc4R <- sum(as.numeric(as.character(apr_dataR$Transaction_Amt2)))
yloc5R <- sum(as.numeric(as.character(may_dataR$Transaction_Amt2)))
yloc6R <- sum(as.numeric(as.character(jun_dataR$Transaction_Amt2)))
yloc7R <- sum(as.numeric(as.character(jul_dataR$Transaction_Amt2)))
yloc8R <- sum(as.numeric(as.character(aug_dataR$Transaction_Amt2)))
yloc9R <- sum(as.numeric(as.character(sep_dataR$Transaction_Amt2)))
yloc10R <- sum(as.numeric(as.character(oct_dataR$Transaction_Amt2)))
yloc11R <- sum(as.numeric(as.character(nov_dataR$Transaction_Amt2)))
yloc12R <- sum(as.numeric(as.character(dec_dataR$Transaction_Amt2)))
xloc <- list("JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC")
ylocB <- list(yloc1B,yloc2B,yloc3B,yloc4B,yloc5B,yloc6B,yloc7B,yloc8B,yloc9B,yloc10B,yloc11B,yloc12B)
ylocR <- list(yloc1R,yloc2R,yloc3R,yloc4R,yloc5R,yloc6R,yloc7R,yloc8R,yloc9R,yloc10R,yloc11R,yloc12R)
data <- data.frame(xloc,ylocB,ylocR)
p <- plot_ly(data, x=~xloc, y=~ylocB, name ='Billed', type = 'scatter', mode='lines',fill='tozeroy') %>%
add_trace(data, x=~xloc, y=~ylocR, name = "Received", type = 'scatter', mode='lines',fill='tozeroy', secondary_y=TRUE) %>%
layout(title= paste(LGT()), xaxis= list(title=paste(lgt())), yaxis= list(title="Amount ($)"))
Я не могу найти, где я неправильно кодирую это.