Databases
loading data
As with API’s a real connection to a remote database is right now not feasible using webR. But we can use duckDB which is a fast in-process analytical database. It has one more advantage: It is locally hosted, which means it is a physical file on your machine. We also use dbplyr which is a database backend that uses the same or similar logic as dplyr for data manipulation with remote data sources.
inspecting the data
Use some of the commands you have already learned to inspect the data! You are on your own here, have fun.
Use the glimpse()
command.
glimpse(mtcars)
Use the head()
command - and check out ?head
to see understand the meaning of the n
argument.
head(mtcars)
Use the print()
command.
print()
The data is well documented, since it is a fairly common toy dataset in R
, so you can find some documentation on it here.
We have just made it available via a duckdb
in-process database, you can also retrieve that data by typing this command. This would take the fun out of playing around with databases though.
data(mtcars)
plotting data
So did it work? You can query the object using the same commands as described above. Another way is of course to plot it, but that is hard when we do not know what variables are in the dataset. Sometimes in those cases, the R base plotting is an excellent way of doing some quick E(xplorative)D(ata)A(nalysis)
play around
You can try to use ggplot on the data. The code below shall give you inspiration on how to start. Maybe you want to use the shape
aesthetic?
See this hint on how to use the shape
aesthetic and plot a rough linear model using geom_smooth()
.
|>
mtcars ggplot(
aes(
x = cyl,
y = hp,
shape = as.factor(gear)
)+
)geom_point()+
geom_smooth(
method = "lm"
)