dwt <- c(2566, 3704, 4008, 5984, 7700, 8034, 8229, 7858, 8408, 8939)
year <- c(1970, 1980, 1990, 2000, 2006, 2007, 2008, 2009, 2010, 2011)
library(ggplot2)
dwt <- c(2566, 3704, 4008, 5984, 7700, 8034, 8229, 7858, 8408, 8939)
year <- c(1970, 1980, 1990, 2000, 2006, 2007, 2008, 2009, 2010, 2011)
df1 <- data.frame(year, dwt)
# ggplot
ggplot(df1,aes(year, dwt)) +
geom_point(color = 'red') +
xlab('Year') +
ylab('Millions of dead weight tons') +
ylim(0,10000)
library(ggplot2)
library(DBI)
library(RMySQL)
# connect to the database
conn <- dbConnect(RMySQL::MySQL(),"www.richardtwatson.com", dbname = "ClassicModels", user = "student", password = "student")
# Query the database and create file for use with R
d <- dbGetQuery(conn,"SELECT productScale from Products;")
# Plot the number of product lines by specifying the appropriate column name
# Internal fill color is blue
# ggplot
ggplot(d,aes(productScale)) +
geom_bar(fill = 'blue') +
xlab('Product scale') +
ylab('Frequency')
library(ggplot2)
library(DBI)
library(RMySQL)
# connect to the database
conn <- dbConnect(RMySQL::MySQL(),"www.richardtwatson.com", dbname = "ClassicModels", user = "student", password = "student")
# Query the database and create file for use with R
d <- dbGetQuery(conn,"SELECT country, sum(quantityOrdered*priceEach) AS orders FROM Orders, OrderDetails, Customers WHERE Orders.orderNumber = OrderDetails.orderNumber and Customers.customerNumber = Orders.customerNumber AND country IN ('Denmark','Finland', 'Norway','Sweden') GROUP BY countr
# ggplot
ggplot(d,aes(country, orders)) +
geom_col(fill = 'yellow') +
xlab('Country') +
ylab('Orders')
library(ggplot2) library(DBI) library(ggmap) # connect to the database conn <- dbConnect(RMySQL::MySQL(),"www.richardtwatson.com", dbname = "ClassicModels", user = "student", password = "student") # Query the database and create file for use with R d <- dbGetQuery(conn,"SELECT y(officeLocation) AS lon, x(officeLocation) AS lat FROM Offices;") map <- get_googlemap('tokyo, japan',marker=d,zoom=5) ggmap(map) + labs(x = 'Longitude', y = 'Latitude') + ggtitle('Japanese offices')
library(ggplot2)
library(readr)
url <- 'http://www.richardtwatson.com/data/manheim.txt'
t <- read_delim(url, delim=',')
# ggplot
ggplot(t,aes(model)) +
geom_bar(fill = 'lightgreen')
library(ggplot2) library(readr) url <- 'http://www.richardtwatson.com/data/wealth.csv' t <- read_delim(url, delim=',') # ggplot ggplot(t, aes(`GDP per capita`)) + geom_histogram(fill='firebrick') ggplot(t, aes(`GDP per capita`)) + geom_histogram(fill='darkorange') ggplot(t, aes(`GDP per capita`)) + geom_histogram(fill='darkolivegreen')
This page is part of the promotional and support material for Data Management (open edition) by Richard T. Watson |