Getting Error when generating plot from 2 data set

Need to create a plot with two data set and now getting an error message as "Error: Invalid input: date_trans works with objects of class Date only"
details are given bellow, how can I solve this issue? Thank you
Codes
ggplot()+
#red
geom_point(data=Nordstrom1, aes(x=DateSale, y=SalePricePSF))+
geom_smooth(data=Nordstrom1, method = "lm", formula = y~poly(x,1), se = F) +
geom_smooth(data=Nordstrom1, method = "lm", formula = y~poly(x,3), se = F, color = "red") +
#green
geom_point(data=NordstromSalesST, aes(x=DateSaleT, y=SalePricePSFT))+
geom_smooth(data=NordstromSalesST, method = "lm", formula = y~poly(x,3), se = F, color = "green")+
theme_economist() +
coord_cartesian(ylim = c(0, 500)) +
theme_bw()+
labs(title = "Market Selection and Price Trend Retail", x = "Sale Date", y = "Sale Price Per SF")

Nordstrom1

A tibble: 10 × 6

Sale DateSale   Anchor      Center                          SalePricePSF Overal…¹


1 2 2009-09-01 Kohl's South Bay Galleria 208. NA
2 6 2010-07-01 Kohl's Elk Grove Commons 239. 7.71
3 20 2011-05-01 Kohl's Capitola Mall 380 6.58
4 24 2011-08-01 Kohl's Parkway Plaza 248. NA
5 25 2011-09-01 JCPenny lhe Village At Orange 105. 6.02
6 37 2012-05-01 Forever 2 i The at Montebello 249. 6.29
7 42 2012-08-01 Walmart La Habra 160. 5.61
8 55 2012-12-01 Kohl's The Crossroads At Pleasant Hill 371. 6.75
9 66 2013-11-01 Kohl's South Bay Galleria 354. 5.26
10 70 2014-02-01 Target Northwood Square 152. 6.1

NordstromSalesST

A tibble: 6 × 4

Address DateSaleT SalePricePSFT PriceSaleT

1 800 Coddingtown Ctr 2005-11-21 00:00:00 105. 10562045
2 900 Coddingtown Ctr 2005-11-21 00:00:00 105. 7882123
3 1363 N Mcdowell Blvd 2017-04-13 00:00:00 186. 16416907
4 8270 Petaluma Hill Rd 2015-04-03 00:00:00 10.8 1200000
5 311 Rohnert Park Expy W 2022-06-24 00:00:00 164. 14000000
6 100 Santa Rosa Plz 2015-07-06 00:00:00 180. 12829406

library(ggplot2)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union

juniors <- data.frame(
  Sale = c(
    2L, 6L, 20L, 24L, 25L, 37L, 42L, 55L,
    66L, 70L
  ),
  DateSale = c(
    "2009-09-01", "2010-07-01", "2011-05-01",
    "2011-08-01", "2011-09-01", "2012-05-01", "2012-08-01", "2012-12-01",
    "2013-11-01", "2014-02-01"
  ), Anchor = c(
    "Kohl's", "Kohl's", "Kohl's",
    "Kohl's", "JCPenny", "Forever", "Walmart", "Kohl's", "Kohl's",
    "Target"
  ), Center = c(
    "South Bay Galleria", "Elk Grove Commons",
    "Capitola Mall", "Parkway Plaza", "lhe Village At Orange", "2 i The atMontebello",
    "La Habra", "TheCrossroads At Pleasant Hill", "South Bay Galleria",
    "Northwood nSquare"
  ), SalePricePSF = c(
    208, 239, 380, 248, 105,
    249, 160, 371, 354, 152
  ), Overa = c(
    NA, 7.71, 6.58, NA, 6.02,
    6.29, 5.61, 6.75, 5.26, 6.1
  )
)

juniors$DateSale <- ymd(juniors$DateSale)

head(juniors)
#>   Sale   DateSale  Anchor                Center SalePricePSF Overa
#> 1    2 2009-09-01  Kohl's    South Bay Galleria          208    NA
#> 2    6 2010-07-01  Kohl's     Elk Grove Commons          239  7.71
#> 3   20 2011-05-01  Kohl's         Capitola Mall          380  6.58
#> 4   24 2011-08-01  Kohl's         Parkway Plaza          248    NA
#> 5   25 2011-09-01 JCPenny lhe Village At Orange          105  6.02
#> 6   37 2012-05-01 Forever  2 i The atMontebello          249  6.29

Created on 2023-01-26 with reprex v2.0.2

I have run above command now and the error message is not showing now but still the plot is not coming

now below is the code

Nordstrom1$DateSale <- ymd(Nordstrom1$DateSale)
NordstromSalesST$DateSaleT <- ymd(NordstromSalesST$DateSaleT)
ggplot()+
#red
geom_point(data=Nordstrom1, aes(DateSale, SalePricePSF))+
geom_smooth(data=Nordstrom1, method = "lm", formula = y~poly(x,1), se = F) +
geom_smooth(data=Nordstrom1, method = "lm", formula = y~poly(x,3), se = F, color = "red") +
#green
geom_point(data=NordstromSalesST, aes(DateSaleT, SalePricePSFT))+
geom_smooth(data=NordstromSalesST, method = "lm", formula = y~poly(x,1), se = F)+
geom_smooth(data=NordstromSalesST, method = "lm", formula = y~poly(x,3), se = F, color = "green")+
theme_economist() +
coord_cartesian(ylim = c(0, 500)) +
theme_bw()+
labs(title = "Market Selection and Price Trend with Retail", x = "Sale Date", y = "Sale Price Per SF")

Errors getting
Error in geom_smooth():
! Problem while computing stat.
:information_source: Error occurred in the 2nd layer.
Caused by error in compute_layer():
! stat_smooth() requires the following missing aesthetics: x and y

When melding two data frames like this

  1. Set the aesthetics in one and let the geoms inherit for it
  2. mapping aesthetics for the other goes `aes(var1,var2), dat)
  3. Make things simpler by using common variable names

Any sequence of points can be connected to create a line that can be decomposed using a Fourier transform in the hope of extracting signal from noise. In the time series domain it is one tool to identify seasonality (recurrent patterns of consecutive events after removing trend and residuals). Where there is no true regularity in the occurrence of events beware of using linear fits, with or without polynomial transforms, there is danger of overfitting.

library(ggplot2)
library(ggthemes)
library(lubridate)
#> 
#> Attaching package: 'lubridate'
#> The following objects are masked from 'package:base':
#> 
#>     date, intersect, setdiff, union

juniors <- data.frame(
  Sale = c(
    2L, 6L, 20L, 24L, 25L, 37L, 42L, 55L,
    66L, 70L
  ),
  DateSale = c(
    "2009-09-01", "2010-07-01", "2011-05-01",
    "2011-08-01", "2011-09-01", "2012-05-01", "2012-08-01", "2012-12-01",
    "2013-11-01", "2014-02-01"
  ), Anchor = c(
    "Kohl's", "Kohl's", "Kohl's",
    "Kohl's", "JCPenny", "Forever", "Walmart", "Kohl's", "Kohl's",
    "Target"
  ), Center = c(
    "South Bay Galleria", "Elk Grove Commons",
    "Capitola Mall", "Parkway Plaza", "lhe Village At Orange", "2 i The atMontebello",
    "La Habra", "TheCrossroads At Pleasant Hill", "South Bay Galleria",
    "Northwood nSquare"
  ), SalePricePSF = c(
    208, 239, 380, 248, 105,
    249, 160, 371, 354, 152
  ), Overa = c(
    NA, 7.71, 6.58, NA, 6.02,
    6.29, 5.61, 6.75, 5.26, 6.1
  )
)

juniors$DateSale <- ymd(juniors$DateSale) |> as.integer()

head(juniors)
#>   Sale DateSale  Anchor                Center SalePricePSF Overa
#> 1    2    14488  Kohl's    South Bay Galleria          208    NA
#> 2    6    14791  Kohl's     Elk Grove Commons          239  7.71
#> 3   20    15095  Kohl's         Capitola Mall          380  6.58
#> 4   24    15187  Kohl's         Parkway Plaza          248    NA
#> 5   25    15218 JCPenny lhe Village At Orange          105  6.02
#> 6   37    15461 Forever  2 i The atMontebello          249  6.29

nordies <- read.csv("~/Desktop/grist.csv")
nordies$DateSaleT <- ymd(nordies$DateSaleT)
nordies
#>                   Address  DateSaleT SalePricePSFT PriceSaleT
#> 1     800 Coddingtown Ctr 2005-11-21         105.0   10562045
#> 2     900 Coddingtown Ctr 2005-11-21         105.0    7882123
#> 3    1363 N Mcdowell Blvd 2017-04-13         186.0   16416907
#> 4   8270 Petaluma Hill Rd 2015-04-03          10.8    1200000
#> 5 311 Rohnert Park Expy W 2022-06-24         164.0   14000000
#> 6      100 Santa Rosa Plz 2015-07-06         180.0   12829406

p <- 
  juniors |> ggplot(aes(DateSale, SalePricePSF), fill = "green") +
  geom_point() +
  geom_smooth(method = "lm", 
              formula = y ~ poly(x,3), 
              se = F, color = "green") +
  geom_point(aes(DateSaleT,SalePricePSFT), nordies) +
  geom_smooth(aes(DateSaleT,SalePricePSFT),nordies, method = "lm", 
              formula = y~poly(x,1), 
              se = F, color = "red") +
  theme_economist() +
  coord_cartesian(ylim = c(0, 500)) +
  theme_bw()+
  labs(title = "Market Selection and Price Trend with Retail", x = "Sale Date", y = "Sale Price Per SF")

p

Created on 2023-01-26 with reprex v2.0.2

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.