KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have the following variables in a data frame: [1] "Type" "I.alt" "idx06" "idx07" "idx08" "farve1" "farve2" If I do: dm <- melt(d, id=c("Type","I.alt")) I get these variables: "Type" "I.alt" "variable" "value" Where "idx06", "idx07", "idx08", "farve1", "farve2" are represented in "variable". But what I really want is something like this: "Type" "I.alt" "variable" "value" "variable2" "value2" Where "farve1" and "farve2" are represented in variable2 and value2. The reason I want to do this, is that I'd like something where the line color is green if the value is falling and red if rising. EDIT: Shane has shown how to reshape the data via two melts merged. But my strategy seams to be ill conceived from the beginning - WRONG in one word. See my comment to Shane's solution. ggplot(dm, aes(x=variable,y=value,group=Type,col=variable2, label=Type,size=I.alt))+ geom_line()+ geom_text(data=subset(dm, variable=="idx08"),hjust=-0.2, size=2.5)+ theme_bw()+ scale_x_discrete(expand=c(0,1))+ opts(legend.position="none") I assume I need to cast the molten frame - but I can't figure it out. The data: d <- structure(list(Type = structure(c(8L, 21L, 23L, 20L, 6L, 14L, 3L, 24L, 2L, 28L, 32L, 22L, 15L, 29L, 1L, 17L, 18L, 33L, 25L, 13L, 30L, 11L, 26L, 9L, 12L, 4L, 5L, 27L, 16L, 19L, 10L, 31L, 7L), .Label = c("Alvorligere vold", "Andre strafferetlige særlove", "Andre tyverier", "Bedrageri", "Brandstiftelse", "Butikstyverier m.v.", "Dokumentfalsk", "Færdselslovovertræd. i øvrigt", "Færdselsuheld med spiritus", "Falsk forklaring i øvrigt", "Forbr. mod off. myndighed m.v.", "Freds- og ærekrænkelser", "Hæleri", "Hærværk", "Indbrud i bank, forretn. m.v.", "Indbrud i fritidshuse, garager mv", "Indbrud i villaer, lejligheder mv", "Love vedr
Tags (comma-separated)
Save Edits
Cancel