我对 R 和 ggplot2 有点陌生,所以这个问题可能有点低级。但是我做了相当多的实验,并没有在网上找到答案,所以我想我会在这里问。
当我将alpha 添加到我的图表时,图表显示如下:
但是,无论我如何更改alpha 的值,我都不会在图表中看到任何变化。我尝试了 alpha=.9 和 alpha=1/10000,图表中没有任何区别。
然而,“阿尔法”一词似乎正在发挥作用。当我从代码中删除“alpha”时,我得到下图:
这是我的代码。谢谢!
library(ggplot2)
library(chron)
argv <- commandArgs(trailingOnly = TRUE)
mydata = read.csv(argv[1])
png(argv[2], height=300, width=470)
timeHMS_formatter <- function(x) { # Takes time in seconds from midnight, converts to HH:MM:SS
h <- floor(x/3600)
m <- floor(x %% 60)
s <- round(60*(x %% 1)) # Round to nearest second
lab <- sprintf('%02d:%02d', h, m, s) # Format the strings as HH:MM:SS
lab <- gsub('^00:', '', lab) # Remove leading 00: if present
lab <- gsub('^0', '', lab) # Remove leading 0 if present
}
dateEPOCH_formatter <- function (y){
epoch <- c(month=1,day=1,year=1970)
chron(floor(y),out.format="mon-year",origin.=epoch)
}
p= ggplot() +
coord_cartesian(xlim=c(min(mydata$day),max(mydata$day)), ylim=c(0,86400)) + # displays data from first email through present
scale_color_hue() +
xlab("Date") +
ylab("Time of Day") +
scale_y_continuous(label=timeHMS_formatter, breaks=seq(0, 86400, 7200)) + # adds tick marks every 2 hours
scale_x_continuous(label=dateEPOCH_formatter, breaks=seq(min(mydata$day), max(mydata$day), 365) ) +
ggtitle("Email Sending Times") + # adds graph title
theme( legend.position = "none", axis.title.x = element_text(vjust=-0.3)) +
layer(
data=mydata,
mapping=aes(x=mydata$day, y=mydata$seconds, alpha=1/2, size=5),
stat="identity",
stat_params=list(),
geom="point",
geom_params=list(),
position=position_identity(),
)
print(p)
dev.off()