library(readr)
trade2013 <- read_csv("trade2013.csv")
## Rows: 22524 Columns: 6
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): country1, country2
## dbl (4): ltrade, lgdp1, lgdp2, ldist
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
library(stargazer)
##
## Please cite as:
##
## Hlavac, Marek (2022). stargazer: Well-Formatted Regression and Summary Statistics Tables.
## R package version 5.2.3. https://CRAN.R-project.org/package=stargazer
model1<-lm(ltrade~ldist,data = trade2013)
stargazer(model1,type = "text",title = "Results")
##
## Results
## ================================================
## Dependent variable:
## ----------------------------
## ltrade
## ------------------------------------------------
## ldist -1.393***
## (0.042)
##
## Constant 12.436***
## (0.342)
##
## ------------------------------------------------
## Observations 13,554
## R2 0.077
## Adjusted R2 0.077
## Residual Std. Error 3.846 (df = 13552)
## F Statistic 1,123.997*** (df = 1; 13552)
## ================================================
## Note: *p<0.1; **p<0.05; ***p<0.01
## You can use the below code to generate the graph.
## Don't forget to replace the 'df' with the name
## of your dataframe
# You need the following package(s):
library("ggplot2")
# The code below will generate the graph:
graph <- ggplot(trade2013, aes(x = ldist, y = ltrade)) +
geom_point()+
geom_smooth(se = TRUE, method = 'lm') +
theme_bw()
graph
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 8970 rows containing non-finite values (`stat_smooth()`).
## Warning: Removed 8970 rows containing missing values (`geom_point()`).

# If you want the plot to be interactive,
# you need the following package(s):
library("plotly")
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
ggplotly(graph)
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 8970 rows containing non-finite values (`stat_smooth()`).
# If you would like to save your graph, you can use:
ggsave('my_graph.pdf', graph, width = 14, height = 14, units = 'cm')
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 8970 rows containing non-finite values (`stat_smooth()`).
## Removed 8970 rows containing missing values (`geom_point()`).