Ggplot show trend line in linear model

library(plotly)

airquality_sept <- airquality[which(airquality$Month == 9),] airquality_sept$Date <- as.Date(paste(airquality_sept$Month, airquality_sept$Day, 1973, sep = "."), format = "%m.%d.%Y") View(airquality_sept) ggplot(airquality_sept, aes(x = Date, y = Wind)) + geom_bar(stat = "identity") + geom_smooth(method = "lm")+ theme(axis.text.x = element_text(angle = 45, vjust = 0.5))

R how to show all x-axis labels

############## showing all x axis labels ###############

ID <- 1:50 A <- runif(50,1,100) df <- data.frame(ID,A) ggplot(df, aes(x = ID, y = A)) + geom_point() + theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) + scale_x_continuous("ID", labels = as.character(ID), breaks = ID)

Plotly Charts Examples

library(plotly)

airquality_sept <- airquality[which(airquality$Month == 9),] airquality_sept$Date <- as.Date(paste(airquality_sept$Month, airquality_sept$Day, 1973, sep = "."), format = "%m.%d.%Y") View(airquality_sept) plot_ly(airquality_sept) %>%
add_trace(x = ~Date, y = ~Wind, type = ‘bar’, name = ‘Wind’,
marker = list(color = ‘#C9EFF9’),
hoverinfo = “text”,
text = ~paste(Wind, ‘ mph’)) %>%
add_trace(x = ~Date, y = ~Temp, type = ‘scatter’, mode = ‘lines’, name = ‘Temperature’, yaxis = ‘y2’,
line = list(color = ‘#45171D’),
hoverinfo = “text”,
text = ~paste(Temp, ‘°F’)) %>%
layout(title = ‘New York Wind and Temperature Measurements for September 1973’,
xaxis = list(title = “”),
yaxis = list(side = ‘left’, title = ‘Wind in mph’, showgrid = FALSE, zeroline = FALSE),
yaxis2 = list(side = ‘right’, overlaying = “y”, title = ‘Temperature in degrees F’, showgrid = FALSE, zeroline = FALSE))

plot_ly(airquality_sept) %>%
add_trace(x = ~Date, y = ~Wind, type = ‘bar’, name = ‘Wind’,
marker = list(color = ‘#C9EFF9’),
hoverinfo = “text”,
text = ~paste(Wind, ‘ mph’)) %>%
layout(title = ‘New York Wind and Temperature Measurements for September 1973’,
xaxis = list(title = “”),
yaxis = list(side = ‘left’, title = ‘Wind in mph’, showgrid = TRUE, zeroline = FALSE),
yaxis2 = list(side = ‘right’, overlaying = “y”, title = ‘Temperature in degrees F’, showgrid = FALSE, zeroline = FALSE))

# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = api_create(p, filename=”multiple-bar_line”)

R trend line, style, other tips

#adding smooth trend linear-trend-line-to-a-scatter-plot-in-r

https://stats.stackexchange.com/questions/30975/how-to-add-non-linear-trend-line-to-a-scatter-plot-in-r

## add moving average in

https://www.quantmod.com/documentation/addMA.html

#running average
https://stackoverflow.com/questions/40857319/plot-running-average-in-ggplot2

## different chart type

https://plot.ly/r/graphing-multiple-chart-types/

## integrate with sql server

Using R in SQL Server Reporting Services (SSRS)