r - Several graphs in ggplot2: Aesthetics must either be length one, or the same length -
I try to plot several dots in the following dataset (downloadable) and a ggplot (code below) I use. I know that there are many explanations, but still I do not seem to get a job because I am confused about what I need to understand the order of the GG Plot.
I know that two ways of raw data may be present: either in wide or long format when I place the data in wide format I get a lot of jobs Something to write (see code and graph below), but when I complain about it long format , ggplot missing values (see code and error message below).
This is my minimum code example:
Library (ggplot2) # WDI_GDP_annual for professional graphs & lt; - WDI [Joe (WDI $ Series. Name == 'GDP Growth (Annual%)'),] Dataset needed from WDI_GDP_annual_short # to remove data & lt; - WDI_GDP_annual [# wide format test_data_long & lt; - Melt (WDI_GDP_annual_short, id = "time") # Long format # (Only successful) Graph with wide format data ggplot (WDI_GDP_annual_short, AES (x = time)) + geom_line (AES (y = Brazil..bra, color = "Brazil .. BRA.", Group = 1)) + GOM_LINE (AES (Y = China..HN., Color = "China ... CHN.", Group = 1)) + Theme (LegendTitle = Element_blank ()) # To plot data in a long time, write several possibilities of graph and write less (but all the complaints) ggplot (data = test_data_long, aes (x = time, y = value, + Geom_line () + theme (legend.title = element_blank ()) ggplot (data = test_data_long, aes (x = time, y = value, color = factor (variable)) + geom_line () + theme (Legend.title = element_blank ()) ggplot (test_data_long, AES (x = time, y = value, color = variable, group = variable)) + geom_line ()
this is yet Is a successful plot, but I do not want to write so much (since I have to get 6 more graphs in this GJPhot):
I know that to use the long format, its How to plot a multiplot, but whatever command I use (see above) I always get the following complaint:
Error: Aesthetics is either a length or data Should have the same length of problem: time
Does anyone know the answer to my question?
To begin with: The strings in your data are ".." Your approximate numeric column, Which will convert the whole column into class
character
(or factor
, your stringsAsFactors
). Settings
If you want to treat NA
as "<", then na.strings = ".."
will be treated with your Read.xxx
will make sure that the column is considered as the numeric
after reading any data set str
should be your friend .
Library (reshape2) library (ggplot2) df & lt; - read.csv (file = "https: //dl.dropboxusercontent.com/u/109495328/WDI_Data.csv", na.strings = "..") str (df) # # df & lt; - read.csv (file = "Compare with https: // Dl.dropboxusercontent.com/u/109495328/WDI_Data.csv") # str (df) # The relevant part of the data df2 & lt; - Melt (subset (df, subset = series .name == "GDP increase (yearly%)", select = -C (timecode, series.code)), id.vers = c ("series name", "Time")) GG Plot (DF2, AES (x = time, y = value, color) = variable, group = variable) + geom_line ()
Comments
Post a Comment