2

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?

1 Answer 1

1

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))

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

I have done 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 need I more modifications. I want to have a point at each data point or values in the data set. How can I do it?
@user3132179 No. I am using the same object , and ggplot2 split it automatically using color aes. Look at my edit for points.
ok so u mean to say point is not possible the way I have done it right?
@user3132179 No I don't mean that. I mean it is simpler to do it the way I did.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.