代码之家  ›  专栏  ›  技术社区  ›  user3496218

ggplot2未使用Plotly正确渲染

  •  0
  • user3496218  · 技术社区  · 7 年前

    代码为:

    library(ggplot2)
    library(dplyr)
    library(plotly)
    library(sqldf)
    library(tidyverse)
    library(lubridate)
    library(rio) #lets you use "import" for any file - without using extension name
    options(scipen =999) #disable scientific notation
    
    
    
    #prepare data:
    
    setwd("C:/Users/hayescod/Desktop/BuysToForecastTracking")
    Buys_To_Forecast <- import("BuysToForecastTrack")
    
    colnames(Buys_To_Forecast) <- c("Date", "BusinessSegment", "Material", "StockNumber", "POCreatedBy", "PlantCode", "StockCategory", "Description", "Excess", "QuantityBought", "WareHouseSalesOrders", "GrandTotal", "Comments" )
    Buys_To_Forecast$PlantCode <-factor(Buys_To_Forecast$PlantCode) #update PlantCode to factor
    
    
    #use SQL to filter and order the data set: 
    
    btf <- sqldf("SELECT Date, 
                         SUM(QuantityBought) AS 'QuantityBought', 
                         Comments
                  FROM   Buys_To_Forecast 
                  GROUP BY Date, Comments
                  ORDER BY Date")
    #use ggplot:
    
    btfnew <- ggplot(data=btf, aes(x=Date, y=QuantityBought, color=Comments, size=QuantityBought)) + 
      geom_point() + 
      facet_grid(Comments~., scales="free")+ 
      ggtitle("Buys To Forecast Review")+
      theme(plot.title = element_text(hjust = 0.5), 
            axis.title.x = element_text(color="DarkBlue", size = 18), 
            axis.title.y = element_text(color="Red", size = 14))
    
    btfnew #display the plot in ggplot
    
    ggplotly(btfnew) #display the plot in Plotly
    
    0 回复  |  直到 7 年前