Reputation: 683
Object 1:
structure(list(Date = structure(c(16026, 16027, 16028, 16029,
16030, 16031, 16032, 16034, 16035, 16036, 16037, 16038, 16039,
16040, 16041, 16042, 16043, 16044, 16045, 16046, 16048, 16049,
16050, 16051, 16052, 16053, 16055, 16056), class = "Date"), Catagory = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("build",
"client"), class = "factor"), User_Name = c(1L, 5L, 6L, 6L, 6L,
7L, 5L, 5L, 3L, 5L, 2L, 4L, 5L, 1L, 6L, 4L, 5L, 4L, 6L, 5L, 12L,
4L, 4L, 3L, 5L, 5L, 3L, 3L)), .Names = c("Date", "Catagory",
"User_Name"), row.names = c(NA, 28L), class = "data.frame")
Object 2:
structure(list(Date = structure(c(16026, 16027, 16028, 16029,
16030, 16031, 16032, 16034, 16035, 16036, 16037, 16038, 16039,
16041, 16042, 16043, 16044, 16045, 16046, 16048, 16049, 16050,
16051, 16052, 16053, 16055, 16056), class = "Date"), Catagory = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("build",
"client"), class = "factor"), User_Name = c(1L, 4L, 6L, 6L, 5L,
7L, 5L, 5L, 3L, 5L, 2L, 4L, 5L, 2L, 3L, 2L, 2L, 5L, 5L, 7L, 3L,
4L, 3L, 4L, 3L, 2L, 2L)), .Names = c("Date", "Catagory", "User_Name"
), row.names = c(NA, 27L), class = "data.frame")
Here I want to plot a single line plot where x-axis would denote time and y-axis would denote the variable User_Name. The time data in both the objects is almost same while the User_Name count is different. I was trying to use ggplot2 to use plot my intended graph. but I don't know how use 2 different object file to plot in a single graph in ggplot2.
NOTE: I tried merging the data in one single object. but some data is getting missed due to mismatch of column length mismatch.
EDITED: I figured it out this way
ggplot()+geom_line(data=build_9,aes(x=Date,y=User_Name),color="red")+geom_line(data=build_10,aes (x=Date,y=User_Name),color="blue")
I want to add point in each values i.e in each data points in the graph. How can I do it?
Upvotes: 2
Views: 1660
Reputation: 121588
No need to merge here, just add a column for each object(data.frame) to characterize it.
obj1$type <- 'obj1'
obj2$type <- 'obj2'
dat <- rbind(obj1,obj2)
Then using ggplot
you can do this:
ggplot(dat,aes(x=Date,y=User_Name))+
geom_point()+
geom_line(aes(color=type))
Upvotes: 1