Use formatting format(pretty(cost), scientific = FALSE, big.mark = ',') R stores dates similarly to stata abline(v = as.Date(c('','','')), lwd = 1:3, Text(x = date, y = cost, pos = 3, xpd = NA, # axis.Date(1, at = seq.Date(min(date), max(date), by = 'year')) Plot(date, cost, xlab = 'Date', ylab = '', axes = FALSE, main = 'a plot'))ĭseq <- seq.Date(as.Date(''), as.Date(''), by = 'year')Īxis.Date(1, at = dseq, labels = format(dseq, format = '%Y')) Thedata <- ame(transactionID, date, cost, company) Geom_vline( xintercept = as.numeric( thedata$date),Īs you can see, I cannot figure out how the coordinates for the xintercept of the geom_vline command work (and can't find it in the official help file), specifically when I want them to be dates (particularly dates that may or not be in the data frame), nor can I figure out how to change the thickness of the line. Geom_text( label = thedata$company, color="blue", vjust = 0) + So then I tried using the ggplot2 package but still can't quite figure it out like I could in Stata: library(ggplot2) I originally tried to do it with the base R installation commands plot() and text(), but it seems like it cannot be done in base R. So far I have pieced together the following code. Is that right? I see some benefits to this, but also some demerits (such as having hundreds of different objects cluttering up your work environment as you explore the data, for instance). But in R it seems that there are extra steps involved where you have to subset the data first and store it as a new object and then run the analysis on that object. TransactionID 3000 & transactionID < 5") and then easily modify them to re-run the analyses or plot the graphs on other various subsets. ![]() rows) indicating transactions (column 1), followed by variables indicating the date of the transaction (column 2), the cost of the transaction (column 3), and the name of the company that initiated the transaction (column 4). The actual dataset is very large, but a sample would look like the following (see R code below), with observations (i.e. The marker labels are of a categorical variable, 'company name'. The scatterplot has the time variable 'date' on the x-axis (mm/dd/yyyy) and the integer variable 'cost' on the y-axis (monetary amount, in USD). I am trying to replicate in R a time-series scatterplot I have created in Stata on a subset of data.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |