Related
This question already has an answer here:
month language in the as.date function
(1 answer)
Closed 5 years ago.
My data frame is:
x=structure(list(V1 = structure(c(33L, 35L, 36L, 37L, 39L, 4L,
6L, 7L, 8L, 10L, 14L, 16L, 18L, 19L, 21L, 25L, 27L, 28L, 29L,
30L, 1L, 17L, 31L, 32L, 34L, 38L, 40L, 2L, 3L, 5L, 9L, 11L, 12L,
13L, 15L, 20L, 22L, 23L, 24L, 26L), .Label = c("1-Feb-71", "10-Feb-71",
"11-Feb-71", "11-Jan-71", "12-Feb-71", "12-Jan-71", "13-Jan-71",
"14-Jan-71", "15-Feb-71", "15-Jan-71", "16-Feb-71", "17-Feb-71",
"18-Feb-71", "18-Jan-71", "19-Feb-71", "19-Jan-71", "2-Feb-71",
"20-Jan-71", "21-Jan-71", "22-Feb-71", "22-Jan-71", "23-Feb-71",
"24-Feb-71", "25-Feb-71", "25-Jan-71", "26-Feb-71", "26-Jan-71",
"27-Jan-71", "28-Jan-71", "29-Jan-71", "3-Feb-71", "4-Feb-71",
"4-Jan-71", "5-Feb-71", "5-Jan-71", "6-Jan-71", "7-Jan-71", "8-Feb-71",
"8-Jan-71", "9-Feb-71"), class = "factor"), V2 = structure(c(1L,
15L, 2L, 4L, 3L, 5L, 10L, 5L, 7L, 12L, 8L, 16L, 16L, 22L, 16L,
19L, 22L, 12L, 17L, 23L, 24L, 24L, 21L, 17L, 19L, 16L, 6L, 11L,
9L, 25L, 25L, 8L, 5L, 13L, 20L, 18L, 16L, 13L, 12L, 14L), .Label = c("7.1359",
"7.1367", "7.1382", "7.1386", "7.1390", "7.1397", "7.1403", "7.1406",
"7.1410", "7.1411", "7.1412", "7.1414", "7.1418", "7.1420", "7.1422",
"7.1429", "7.1431", "7.1434", "7.1435", "7.1437", "7.1439", "7.1443",
"7.1445", "7.1465", "ND"), class = "factor")), .Names = c("V1",
"V2"), class = "data.frame", row.names = c(NA, -40L))
I am trying to convert column V1 to Date, but it is not working. Ive been looking some topics but it just doesnt work.
This my code:
x$V1 <- as.Date(x$V1, format="%d-%b-%y")
It works for some rows of V1 column but not for others.
Any help?
In my version of R, the conversion in your example only works for January and not for February. I think it is related to the language.
For example, in French, February is coded as fév and so Feb is not recognized.
Once I did:
x$V1=gsub("Feb", "fév", x$V1)
it worked.
It probably depends on which language your version of R uses.
I have adjacency list in the form of:
1. 3,4
2. 4
3. 1,4
4. 1,2,3
and I want to transform into adjacency matrix using R.
I have tried various commands like transformation of adjacency list to igraph object and then retransformation of igraph to adjacency matrix, but the obtained adjacency matrix is S4 class. I want simple commands to transform adjacency list to adjacency matrix in R.
data
list(c(1L, 3L, 4L, 8L, 14L, 31L, 2L, 29L, 33L, 7L, 11L, 17L,
5L, 6L, 34L), c(2L, 3L, 4L, 8L, 9L, 12L, 13L, 14L, 18L, 22L,
1L, 10L, 33L, 34L), c(2L, 3L, 4L, 8L, 9L, 12L, 13L, 14L, 18L,
20L, 22L, 32L, 1L, 31L, 34L, 24L), c(2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 1L, 31L, 10L, 28L,
29L), c(4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L,
22L, 32L, 1L, 17L), c(4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L,
14L, 18L, 20L, 22L, 32L, 1L, 17L), c(4L, 5L, 6L, 7L, 8L, 9L,
11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 1L, 17L), c(2L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 1L,
31L, 10L, 28L, 29L), c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L,
13L, 14L, 18L, 20L, 22L, 32L, 10L, 28L, 29L, 33L, 34L, 15L, 16L,
19L, 21L, 23L, 24L, 30L, 31L, 27L), c(2L, 4L, 8L, 9L, 10L, 14L,
28L, 29L, 33L, 15L, 16L, 19L, 20L, 21L, 23L, 24L, 27L, 30L, 31L,
32L), c(4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L,
22L, 32L, 1L, 17L), c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L,
13L, 14L, 18L, 20L, 22L, 32L), c(2L, 3L, 4L, 5L, 6L, 7L, 8L,
9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L), c(2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 1L, 31L,
10L, 28L, 29L, 33L, 15L, 16L, 19L, 21L, 23L, 24L, 27L, 30L),
c(9L, 15L, 16L, 19L, 21L, 23L, 24L, 30L, 31L, 32L, 10L, 14L,
20L, 27L, 28L, 29L), c(9L, 15L, 16L, 19L, 21L, 23L, 24L,
30L, 31L, 32L, 10L, 14L, 20L, 27L, 28L, 29L), c(1L, 7L, 11L,
17L, 5L, 6L), c(2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L,
13L, 14L, 18L, 20L, 22L, 32L, 31L), c(9L, 15L, 16L, 19L,
21L, 23L, 24L, 30L, 31L, 32L, 10L, 14L, 20L, 27L, 28L, 29L
), c(3L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L,
20L, 22L, 32L, 31L, 10L, 15L, 16L, 19L, 21L, 23L, 24L, 27L,
28L, 29L, 30L), c(9L, 15L, 16L, 19L, 21L, 23L, 24L, 30L,
31L, 32L, 10L, 14L, 20L, 27L, 28L, 29L), c(2L, 3L, 4L, 5L,
6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L, 20L, 22L, 32L, 31L
), c(9L, 15L, 16L, 19L, 21L, 23L, 24L, 30L, 31L, 32L, 10L,
14L, 20L, 27L, 28L, 29L), c(24L, 25L, 32L, 3L, 34L, 27L,
33L, 9L, 15L, 16L, 19L, 21L, 23L, 30L, 31L, 10L, 14L, 20L,
28L, 29L), c(24L, 25L, 32L, 34L, 26L, 29L), c(26L, 28L, 30L,
33L, 34L, 32L, 25L, 29L), c(24L, 27L, 33L, 9L, 10L, 14L,
15L, 16L, 19L, 20L, 21L, 23L, 28L, 29L, 30L, 31L, 32L), c(4L,
8L, 9L, 10L, 14L, 28L, 29L, 33L, 26L, 30L, 32L, 15L, 16L,
19L, 20L, 21L, 23L, 24L, 27L, 31L), c(1L, 4L, 8L, 9L, 10L,
14L, 28L, 29L, 33L, 25L, 26L, 15L, 16L, 19L, 20L, 21L, 23L,
24L, 27L, 30L, 31L, 32L), c(26L, 28L, 30L, 33L, 34L, 9L,
15L, 16L, 19L, 21L, 23L, 24L, 31L, 32L, 10L, 14L, 20L, 27L,
29L), c(1L, 3L, 4L, 8L, 14L, 18L, 20L, 22L, 31L, 33L, 34L,
9L, 15L, 16L, 19L, 21L, 23L, 24L, 30L, 32L, 10L, 27L, 28L,
29L), c(3L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L, 14L, 18L,
20L, 22L, 32L, 26L, 28L, 24L, 25L, 15L, 16L, 19L, 21L, 23L,
30L, 31L, 10L, 27L, 29L), c(1L, 2L, 9L, 10L, 14L, 28L, 29L,
33L, 31L, 34L, 26L, 30L, 24L, 27L), c(1L, 3L, 31L, 33L, 34L,
2L, 26L, 30L, 24L, 25L, 9L))
Suppose el is a list of edge list:
el = list(c(3,4),
c(2,4),
c(1,4),
c(1,2,3))
#Get the matrix dimension
dim <- length(el)
m <- sapply(el, function(x) { r<-rep(0,dim); r[unlist(x)]<-1;r})
[,1] [,2] [,3] [,4]
[1,] 0 0 1 1
[2,] 0 1 0 1
[3,] 1 0 0 1
[4,] 1 1 1 0
I am attempting to create and output as pdfs a list of 64 items. My data takes the form:
QQJAN List of 64
file1: List of 2
..$x: num [1:161] 96.7 96.8 97.5 ...
..$y: num [1:161] 9.3 10.3 17.3 ...
..................................................................
file64: List of 2
..$x: num [1:161] 42.6 59.9 70.4 ...
..$y: num [1:161] 9.3 10.3 17.3 ...
I can do this for any single item in the list using:
plot(QQJAN$file1)
and can then output these files to my working directory as pdfs, but how can all 64 files in the list be plotted and outputted with their names, i.e. file1.pdf, file 2.pdf etc.
Can the lapply function be used here?
A reproducible example:
QQJAN$file1$x=c(1,2,3,4)
QQJAN$file1$y=c(2,4,5,6)
QQJAN$file2$x=c(2,2,3,5)
QQJAN$file2$y=c(2,4,5,6)
Not tested due to lack of a reproducible example:
for (i in seq_along(QQJAN)) {
pdf(sprintf("plot%i.pdf", i)) #or pdf(paste0(names(QQJAN)[i], ".pdf"))
plot(QQJAN[[i]])
dev.off()
}
If you are only interested in side effects, such as plotting, a for loop is usually appropriate. You should use lapply if you need a return value.
We can use lapply to loop over the names of the list elements, create the pdf file by pasteing the individual names with .pdf, subset the list (QQJAN[[x]]), plot.
invisible(lapply(names(QQJAN), function(x) {
pdf(paste0(x, '.pdf'))
plot(QQJAN[[x]])
dev.off()}))
data
QQJAN <- structure(list(file1 = structure(list(x = c(6L, 5L, 15L, 11L,
14L, 19L, 6L, 16L, 17L, 6L, 13L, 8L, 14L, 14L, 7L, 19L, 4L, 1L,
11L, 3L, 2L, 12L, 15L, 3L, 5L, 14L, 2L, 12L, 13L, 1L, 7L, 5L,
8L, 3L, 19L, 5L, 15L, 13L, 14L, 20L), y = c(29L, 23L, 17L, 14L,
3L, 5L, 24L, 22L, 16L, 21L, 28L, 52L, 28L, 43L, 33L, 60L, 28L,
18L, 11L, 9L, 30L, 15L, 17L, 8L, 44L, 19L, 57L, 59L, 45L, 30L,
9L, 13L, 1L, 60L, 39L, 21L, 35L, 50L, 3L, 44L)), .Names = c("x",
"y")), file2 = structure(list(x = c(11L, 3L, 11L, 5L, 8L, 7L,
6L, 18L, 8L, 17L, 7L, 15L, 19L, 3L, 10L, 12L, 13L, 2L, 9L, 10L,
15L, 13L, 3L, 6L, 16L, 1L, 20L, 5L, 9L, 4L, 12L, 1L, 6L, 13L,
18L, 7L, 18L, 19L, 15L, 13L), y = c(56L, 31L, 40L, 43L, 20L,
45L, 55L, 8L, 43L, 26L, 7L, 52L, 7L, 31L, 11L, 14L, 55L, 26L,
4L, 42L, 34L, 44L, 12L, 4L, 30L, 60L, 23L, 44L, 29L, 55L, 6L,
37L, 11L, 14L, 36L, 52L, 28L, 22L, 31L, 33L)), .Names = c("x",
"y"))), .Names = c("file1", "file2"))
I hope you all can help me.
I have a list with two data frames -- contests and expvar. In the data frame contests, each row is a match with the first column being the winner of the match, and the second column being the loser of the match. In the data frame expvar I have player-specific predictor variables. These are all numbers. I am trying to use the BradleyTerry2 package to analyze my data. Here is the code I am using:
a <- data.frame(read.csv(file.choose()))
b <- data.frame(read.csv(file.choose()))
ablist <- list(contests=a, expvar=b)
Model <- BTm(1, winner, loser, ~level2[..]+(1|..), data=ablist)
This is the error I get:
Error in Diff(player1, player2, formula, id, data, separate.ability, refcat, :
'player1$..' and 'player2$..' must be factors with the same levels
My question is, what am I doing wrong? I have tried many things, but I am not sure what this error means. Should I change my variables into factors? Why/how? The winners and losers all have the same categories of predictor variables.
Here is my output for dput(a)
structure(list(winner = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L,
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L,
9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L,
11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 12L,
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L,
14L, 14L, 14L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L,
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 19L,
19L, 19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 22L,
22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L,
24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 25L,
25L, 25L, 25L, 25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L,
26L, 27L, 27L, 27L, 27L, 28L, 28L, 29L, 29L, 29L, 29L, 29L, 29L,
29L, 29L, 29L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L, 30L,
30L, 30L, 30L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 31L, 23L, 13L,
20L, 20L), .Label = c("Arizona Cardinals", "Atlanta Falcons",
"Baltimore Ravens", "Buffalo Bills", "Carolina Panthers", "Chicago Bears",
"Cincinnati Bengals", "Cleveland Browns", "Dallas Cowboys", "Denver Broncos",
"Green Bay Packers", "Houston Texans", "Indianapolis Colts",
"Jacksonville Jaguars", "Kansas City Chiefs", "Miami Dolphins",
"Minnesota Vikings", "New England Patriots", "New Orleans Saints",
"New York Giants", "New York Jets", "Oakland Raiders", "Philadelphia Eagles",
"Pittsburgh Steelers", "San Diego Chargers", "San Francisco 49ers",
"Seattle Seahawks", "St. Louis Rams", "Tampa Bay Buccaneers",
"Tennessee Titans", "Washington Redskins"), class = "factor"),
loser = structure(c(4L, 9L, 17L, 27L, 27L, 28L, 28L, 29L,
29L, 5L, 6L, 11L, 12L, 16L, 18L, 20L, 23L, 26L, 29L, 30L,
7L, 7L, 8L, 8L, 9L, 13L, 15L, 17L, 23L, 24L, 32L, 10L, 15L,
16L, 23L, 26L, 28L, 29L, 1L, 2L, 6L, 10L, 11L, 12L, 16L,
20L, 20L, 23L, 26L, 30L, 11L, 11L, 12L, 14L, 15L, 18L, 20L,
24L, 29L, 8L, 15L, 16L, 32L, 4L, 7L, 15L, 21L, 7L, 8L, 12L,
21L, 24L, 27L, 28L, 30L, 32L, 2L, 8L, 16L, 20L, 22L, 23L,
26L, 30L, 6L, 11L, 11L, 14L, 18L, 28L, 6L, 7L, 8L, 11L, 12L,
15L, 17L, 31L, 3L, 7L, 8L, 11L, 13L, 13L, 15L, 19L, 25L,
26L, 31L, 10L, 11L, 12L, 13L, 14L, 10L, 23L, 4L, 4L, 10L,
16L, 19L, 22L, 23L, 26L, 27L, 28L, 29L, 1L, 5L, 6L, 11L,
11L, 12L, 13L, 15L, 20L, 21L, 1L, 4L, 4L, 10L, 16L, 17L,
22L, 23L, 27L, 28L, 29L, 2L, 11L, 12L, 16L, 23L, 26L, 27L,
30L, 1L, 3L, 5L, 7L, 9L, 24L, 25L, 27L, 28L, 32L, 1L, 4L,
4L, 7L, 16L, 17L, 19L, 29L, 31L, 10L, 13L, 16L, 22L, 30L,
1L, 2L, 8L, 9L, 21L, 25L, 27L, 28L, 29L, 3L, 3L, 7L, 7L,
8L, 8L, 9L, 13L, 15L, 19L, 26L, 32L, 10L, 16L, 16L, 19L,
22L, 23L, 23L, 30L, 4L, 11L, 22L, 28L, 29L, 29L, 32L, 22L,
27L, 29L, 29L, 9L, 32L, 2L, 5L, 6L, 11L, 12L, 16L, 18L, 20L,
28L, 3L, 6L, 7L, 8L, 11L, 12L, 13L, 14L, 15L, 15L, 16L, 18L,
25L, 1L, 8L, 9L, 11L, 20L, 24L, 24L, 28L, 7L, 18L, 29L, 32L
), .Label = c("Arizona Cardinals", "Atlanta Falcons", "Baltimore Ravens",
"Buffalo Bills", "Carolina Panthers", "Chicago Bears", "Cincinnati Bengals",
"Cleveland Browns", "Dallas Cowboys", "Denver Broncos", "Detroit Lions",
"Green Bay Packers", "Houston Texans", "Indianapolis Colts",
"Jacksonville Jaguars", "Kansas City Chiefs", "Miami Dolphins",
"Minnesota Vikings", "New England Patriots", "New Orleans Saints",
"New York Giants", "New York Jets", "Oakland Raiders", "Philadelphia Eagles",
"Pittsburgh Steelers", "San Diego Chargers", "San Francisco 49ers",
"Seattle Seahawks", "St. Louis Rams", "Tampa Bay Buccaneers",
"Tennessee Titans", "Washington Redskins"), class = "factor")), .Names = c("winner",
"loser"), row.names = c(NA, -256L), class = "data.frame")
Here it is for dput(b)
structure(list(X = structure(1:32, .Label = c("Arizona Cardinals",
"Atlanta Falcons", "Baltimore Ravens", "Buffalo Bills", "Carolina Panthers",
"Chicago Bears", "Cincinnati Bengals", "Cleveland Browns", "Dallas Cowboys",
"Denver Broncos", "Detroit Lions", "Green Bay Packers", "Houston Texans",
"Indianapolis Colts", "Jacksonville Jaguars", "Kansas City Chiefs",
"Miami Dolphins", "Minnesota Vikings", "New England Patriots",
"New Orleans Saints", "New York Giants", "New York Jets", "Oakland Raiders",
"Philadelphia Eagles", "Pittsburgh Steelers", "San Diego Chargers",
"San Francisco 49ers", "Seattle Seahawks", "St. Louis Rams",
"Tampa Bay Buccaneers", "Tennessee Titans", "Washington Redskins"
), class = "factor"), id = 1:32, high = c(0L, 0L, 0L, 0L, 0L,
1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 0L, 0L, 0L, 0L, 0L,
0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L), level2 = c(0, 0.67,
0, 0.33, 0.25, 0, 0, 0.25, 0.33, 0, 0.25, 0, 0, 0.5, 0, 0, 0.25,
0.33, 0, 0, 0, 0, 0, 0, 0, 0.67, 0.25, 0, 0.2, 0, 0, 0.6), level3 = c(0.25,
0.4, 0.36, 0.3, 0.11, 0.56, 0.38, 0.5, 0.22, 0.33, 0.6, 0.3,
0.57, 0.38, 0.29, 0.43, 0.3, 0.33, 0.29, 0.14, 0.2, 0.22, 0.33,
0.22, 0.5, 0.27, 0.4, 0.2, 0.43, 0.43, 0.33, 0.44)), .Names = c("X",
"id", "high", "level2", "level3"), row.names = c(NA, -32L), class = "data.frame"
Thank you
I also got stuck with this error message for the 'BTm' function. The problem can be resolved by defining the levels. (levels are a definable attribute for functions of type factor). Try setting levels for player1 & player2:
levels(contests[,1]) <- unique(c(contests[,1], contests[,2]))
levels(contests[,2]) <- unique(c(contests[,1], contests[,2]))
Sorry I couldn't help 3 years ago ;)
I have the following data:
points <- structure(list(A = structure(c(1L, 1L, 2L, 2L, 3L, 4L,
4L, 5L, 5L, 6L, 6L, 7L, 8L, 9L, 9L, 10L, 11L, 12L, 12L, 13L,
14L, 15L, 16L, 16L, 17L, 17L, 18L, 18L, 19L, 19L, 20L, 21L, 21L,
22L, 23L, 24L, 24L, 25L, 26L, 26L, 27L, 28L, 29L, 30L, 30L, 31L,
32L, 32L, 33L, 34L, 34L, 35L, 35L, 36L, 36L, 37L, 37L, 38L, 38L,
39L, 39L, 40L, 41L), .Label = c("00017dd3-f55e-e011-854c-00237de2db9e",
"0005f624-565a-e011-854c-00237de2db9e", "0007b82f-bfe0-4b55-963e-be5a2a1e7f7b",
"00095b52-fd0a-e011-9264-00237de2db9e", "00098835-9554-4898-8d4b-82d42b8b4464",
"000a727f-8334-e011-854c-00237de2db9e", "000c0a31-f459-4365-aa3a-1978deb89f67",
"000e36a4-6e56-4851-8d36-2caf0bdd63ec", "000f05a6-cf94-4518-8de7-1773cbea8198",
"00105574-a775-43e8-8472-c8b294e46786", "00112a96-3c47-409c-83bd-6f30d8d77100",
"0012f133-f68e-e011-986b-78e7d1fa76f8", "0012f899-1c45-4917-90b7-11bea31e467e",
"0014606b-17b7-46d6-957f-e23b43fcc773", "001478e2-3e50-486c-ae3b-d1ceb36f0fd0",
"00159bab-ce82-454a-9343-f7d8f1500a68", "0015b84e-a48d-443e-936e-cabdb80604dc",
"0018f8ba-c289-4483-bf74-5cd0e6c6ae9e", "0019487f-f31e-4e3e-b499-fd48077f71f9",
"00199523-c42f-47fd-a44a-066fb726f6dd", "0019dace-41e1-439f-8b73-328d02537fe7",
"001a346e-2a15-45d4-9fb1-6b4e2448d362", "001b0c90-5c86-4290-bad3-0d6794a6bfe8",
"001c0d0d-3059-e011-854c-00237de2db9e", "001c9cbb-8c79-4cbf-bc50-219a70ab20b8",
"001dcf83-7492-e011-986b-78e7d1fa76f8", "001dd5cf-3e3b-4ceb-823c-346c15f88878",
"001e0ef7-b977-436a-ab20-8c4af4f5b230", "001fc407-da48-4c42-9325-7756b160cbbd",
"001fdaa1-9471-e011-81d2-78e7d1fa76f8", "0020029f-2667-4c03-b99f-d803eccd27d4",
"00218e00-896e-e011-81d2-78e7d1fa76f8", "002196af-60c7-4baf-abdb-589b3a481686",
"0021a908-7ff6-df11-9264-00237de2db9e", "0021bced-909a-e011-986b-78e7d1fa76f8",
"0021f0fb-cb9f-e011-986b-78e7d1fa76f8", "00228254-9b20-4d40-a4a5-a7c608f81dfa",
"002357ba-5656-4308-bb92-6cc97f50d7aa", "0025eafd-a64f-e011-854c-00237de2db9e",
"0026b36c-ebc2-43f0-a0f7-72f43b70530b", "00277e09-543e-449a-8571-38f71a21cee2"
), class = "factor"), B = structure(c(10L, 10L, 27L,
27L, 28L, 23L, 23L, 38L, 38L, 24L, 24L, 19L, 35L, 26L, 26L, 28L,
5L, 36L, 36L, 21L, 11L, 1L, 14L, 14L, 4L, 4L, 9L, 9L, 16L, 16L,
3L, 7L, 7L, 13L, 37L, 17L, 17L, 29L, 15L, 15L, 12L, 31L, 32L,
8L, 8L, 2L, 30L, 30L, 39L, 6L, 6L, 22L, 22L, 20L, 20L, 34L, 34L,
18L, 18L, 33L, 33L, 25L, 29L), .Label = c("Aashu", "Actonica Studio",
"appyminds", "blackink", "BroeckiE", "Challenge Solutions LLC",
"CPP_MSP", "Datentechnik Innovation GmbH", "DerekM", "Dimension Srl",
"Dmitry Kazarin", "edg3", "fruitymo", "Geckosan", "Genera Interactive SL",
"HandyWare", "Infinite Square", "JTO.C Sq.", "JuJuZ", "Kitten Flavour",
"Krofita", "Mark Agholor", "MCTronix.com", "Michael Snow", "michaloxo",
"mobilewares.net", "NotoMedia LLC", "OKR", "P.F. CHAUVET", "Panoylhs",
"Pratik Gandhi", "raavr", "ReadBooks", "RGP", "Seesmic", "The KeitaCorp",
"viileetek", "Violineage", "Yalla Apps"), class = "factor"),
Date = structure(c(1302926400, 1302926400, 1302408000,
1302408000, 1327467600, 1292994000, 1292994000, 1322370000,
1322370000, 1297486800, 1297486800, 1326949200, 1321333200,
1314763200, 1314763200, 1328418000, 1327381200, 1307505600,
1307505600, 1325221200, 1324530000, 1327381200, 1326862800,
1326862800, 1326171600, 1326171600, 1325566800, 1325566800,
1327122000, 1327122000, 1320379200, 1324702800, 1324702800,
1327726800, 1327986000, 1301544000, 1301544000, 1332302400,
1308369600, 1308369600, 1325912400, 1331611200, 1325912400,
1304481600, 1304481600, 1325653200, 1304395200, 1304395200,
1322542800, 1294117200, 1294117200, 1309147200, 1309147200,
1309320000, 1309320000, 1313208000, 1313208000, 1325739600,
1325739600, 1300334400, 1300334400, 1325826000, 1321938000
), class = c("POSIXct", "POSIXt"), tzone = "")), .Names = c("A",
"B", "Date"), row.names = c(NA, -63L), class = "data.frame")
I am trying to draw a scatter plot with the Y-axis sorted based on the date field. However, I am only able to do the following where I treat A as a factor. Any suggestions on how to achieve this?
p = ggplot(points, aes(Date, factor(A))) +
geom_point(aes(colour=factor(A)), size=1.8) +
scale_shape(solid=FALSE) +
scale_y_discrete("", breaks=NA)
The error comes when you ask ggplot to consider a date value as a discrete variable after just swapping the x and y positions. It goes away when you remove that:
p = ggplot(points, aes(x=A, y=Date)) +
geom_point(aes(colour=factor(A)), size=1.8) +
scale_shape(solid=FALSE)
p
Or you can get rid of the lines by applying the discrete axis call to the x-axis:
p = ggplot(points, aes(x=A, y=Date)) +
geom_point(aes(colour=factor(A)), size=1.8) +
scale_shape(solid=FALSE) +
scale_x_discrete("", breaks=NULL)
P
Unfortunately the title of the question doesn't seem to have a very clear connection to the text of the question, so I cannot tell if this was what you were asking for.