#plotly trying library(plotly) library(dplyr)
unrate_plot <- unrate_date %>% mutate(series = “Unemployment Rate (%)”, value = UNRATE)
pcepi_plot <- pcepi_date %>% mutate(series = “PCE Price Index”, value = PCEPI)
p <- plot_ly() %>% add_lines(data = unrate_plot, x = ~observation_date, y = ~value, name = “Unemployment Rate (%)”, line = list(color = “navyblue”), yaxis = “y”) %>% add_lines(data = pcepi_plot, x = ~observation_date, y = ~value, name = “PCE Price Index”, line = list(color = “indianred”), yaxis = “y2”) %>%
layout( title = list( text = “Unemployment rate &
PCEPI
Apr.2020–Apr.2025”, x = 0.5, xanchor = “center” ),
xaxis = list(title = “Date”), yaxis = list(title = “Unemployment Rate
(%)”, side = “left”, color = “navyblue”), yaxis2 = list(title = “PCE
Price Index”, overlaying = “y”, side = “right”, color =
“indianred”),
legend = list(
title = list(text = "<b>Illustrator</b>"),
x = 0.02,
y = 0.98,
xanchor = "left",
bgcolor = "rgba(255,255,255,0.5)"
)
)
p
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
#plotly trying library(plotly) library(dplyr)
unrate_plot <- unrate_date %>% mutate(series = “Unemployment Rate (%)”, value = UNRATE)
pcepi_plot <- pcepi_date %>% mutate(series = “PCE Price Index”, value = PCEPI)
p <- plot_ly() %>% add_lines(data = unrate_plot, x = ~observation_date, y = ~value, name = “Unemployment Rate (%)”, line = list(color = “navyblue”), yaxis = “y”) %>% add_lines(data = pcepi_plot, x = ~observation_date, y = ~value, name = “PCE Price Index”, line = list(color = “indianred”), yaxis = “y2”) %>%
layout( title = list( text = “Unemployment rate &
PCEPI
Apr.2020–Apr.2025”, x = 0.5, xanchor = “center” ),
xaxis = list(title = “Date”), yaxis = list(title = “Unemployment Rate
(%)”, side = “left”, color = “navyblue”), yaxis2 = list(title = “PCE
Price Index”, overlaying = “y”, side = “right”, color =
“indianred”),
legend = list(
title = list(text = "<b>Illustrator</b>"),
x = 0.02,
y = 0.98,
xanchor = "left",
bgcolor = "rgba(255,255,255,0.5)"
)
)
p Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.