Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to get data from two separate dataframes onto the same scatterplot. I have seen solutions in R that use something like:

ggplot() + geom_point(data = df1, aes(df1.x,df2.y)) + geom_point(data = df2,aes(df2.x, df2.y))

But in python, with the ggplot module, I get errors when I try to use ggplot() with no args. Is this just a limitation of the module? I know I can likely use another tool to do the plotting but I would prefer a ggplot solution if possible.

My first data frame consists of Voltage information every 2 minutes and temperature information every one hour, so combining the two dataframes is not 1 to 1. Also, I would prefer to stick with Python because the rest of my solution is in python.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

Just giving one dataframe as argument for ggplot() and the other inside the second geom_point declaration should do the work:

ggplot(aes(x='x', y='y'), data=df1) + geom_point() + 
       geom_point(aes(x='x', y='y'), data=df2)

(I prefer using the column name notation, I think is more elegant, but this is just a personal preference)

share|improve this answer
    
That works, thank you. So, the 'base' ggplot needs its own dataset and subsequent geom_point() usages can add different datasets. Is that the gist of it? –  scld May 21 '14 at 13:30
    
It also surprised me the first time I realised about that. I don't really know the reason behind not allowing an empty ggplot() and including data in subsequent geom_point(). Maybe one of the main developers of the project could answer this better. –  MonkeyButter May 22 '14 at 6:43
    
I think the error on an empty ggplot() call comes from the time where it wasn't allowed to specify a new df in each geom. –  Jan Schulz Jan 6 at 21:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.