我正在处理成千上万的气象时间序列数据(示例数据可从此处下载)
https://dl.dropboxusercontent.com/s/bxioonfzqa4np6y/timeSeries.txt
在我的Linux Mint电脑上(64位,8GB RAM,双核2.6 GHz),使用ggplot2绘制这些数据花费了很长时间。我想知道是否有加速或更好的绘制方式?非常感谢您提供任何建议!
这是我目前正在使用的代码:
这是我目前正在使用的代码:
##############################################################################
#### load required libraries
library(RCurl)
library(reshape2)
library(dplyr)
library(ggplot2)
##############################################################################
#### Read data from URL
dataURL <- "https://dl.dropboxusercontent.com/s/bxioonfzqa4np6y/timeSeries.txt"
tmp <- getURL(dataURL)
df <- tbl_df(read.table(text = tmp, header = TRUE))
df
##############################################################################
#### Plot time series using ggplot2
# Melt the data by date first
df_melt <- melt(df, id = "date")
str(df_melt)
df_plot <- ggplot(data = df_melt, aes(x = date, y = value, color = variable)) +
geom_point() +
scale_colour_discrete("Station #") +
xlab("Date") +
ylab("Daily Precipitation [mm]") +
ggtitle("Daily precipitation from 1915 to 2011") +
theme(plot.title = element_text(size = 16, face = "bold", vjust = 2)) + # Change size & distance of the title
theme(axis.text.x = element_text(angle = 0, size = 12, vjust = 0.5)) + # Change size of tick text
theme(axis.text.y = element_text(angle = 0, size = 12, vjust = 0.5)) +
theme( # Move x- & y-axis lables away from the axises
axis.title.x = element_text(size = 14, color = "black", vjust = -0.35),
axis.title.y = element_text(size = 14, color = "black", vjust = 0.35)) +
theme(legend.title = element_text(colour = "chocolate", size = 14, face = "bold")) + # Change Legend text size
guides(colour = guide_legend(override.aes = list(size = 4))) + # Change legend symbol size
guides(fill = guide_legend(ncols = 2))
df_plot