r - ggplot2 stacked area line charts producing odd lines and holes -
i have data set that's structured follows:
year color toyota honda ford 2011 blue 66 75 13 2011 red 75 91 62 2011 green 65 26 57 2012 blue 64 23 10 2012 red 84 8 62 2012 green 67 21 62 2013 blue 31 74 49 2013 red 48 43 35 2013 green 57 62 74 2014 blue 59 100 32 2014 red 72 47 67 2014 green 97 24 70 2015 blue 31 0 79 2015 red 60 35 74 2015 green 51 2 28
(my actual data, presented in chart images below, larger , has 100s of "colors" i'm simplifying here can merely understand structure.)
i trying make stacked area line chart shows how many cars of each color produced on time specific company. (i.e. each company has own chart in x axis = years, y axis = cars produced).
i run code:
qplot(year, toyota, data = dataname, fill = color, group = color, geom= "area", position = "stack") + geom_area() + theme(legend.position = "none")
however, every company's chart has issues. there seemingly random cut-out holes lines cut across top of layers.
i'm confused why happening or possible (especially holes... won't data stack down?) if made companies long rather wide in data structure?
even 0 values, should not have errors. took data , added 0's in honda column sporadically.
the code (using ggplot2)
library(ggplot2) df <- read.csv("cartest.csv", header = true) ggplot(data=df,aes(x=year,y=h,fill=color)) + geom_area() + ggtitle("car test")
if importing data csv or tsv , data columns numeric should not have issue. if imported .character can convert using:
df$h <- as.numeric(df$h)
Comments
Post a Comment