[R] Combining dataframes with different row numbers and plotting with ggplot2

Michael Dewey lists at dewey.myzen.co.uk
Sat Jan 9 15:08:05 CET 2016


Dear Maryam

If you just need all the values of size would
c(df1$size, df2$size)
work?

On 08/01/2016 21:44, maryam moazam wrote:
> Dear Sir / Madam,
>
> I have just come to the amazing R software, so please be patient if my
> question is basic for you. I have 2 text file (say 1.txt and 2.txt), each
> file containing 2 columns and different row numbers, like below
>
> case size
> case1 120
> case2 120
> case3 121
> case4 121
> case5 121
> case6 122
> case7 122
> case8 123
>
> I would like to have a one plot for all text files, with x-axis shows the
> size between 300-1200 with the interval of 200 (300,500,700,900,1200) and
> size between 1201-1500 with the interval of 1000. For dataframes with the
> equal row numbers, the following codes worked well,
>
> df1 = data.frame("1.txt", header=T)
> df2 = data.frame("2.txt", header=T)
> *combining two dataframes with equal row number*
>
> df = data.frame(df1$size,df2$size)
> library(reshape)
> melted <- melt(df)
>
> ggplot(data=melted, aes(value))+aes(fill=variable)+ geom_histogram
> (binwidth =500)+
>
> +scale_x_continuous(breaks=c(seq(300,1000,by=200),seq(1001,15000,by=1000)))
>
>
> but I couldn't reproduce the plot with these codes for dataframes with
> different row number. I think the problem is* how to combine datafrmaes
> with the different row number*, could you please help me out on this issue?
>
> Thank you in advance
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Michael
http://www.dewey.myzen.co.uk/home.html



More information about the R-help mailing list