ayush
ayush

Reputation: 343

plotting only selected class from multiple CSV files in R (ggplot)

Let's say I have imported 2(or more) CSV files having similar columns. Let's say I have "A", "B" and "class" columns in each of the CSV files but the values are different. Let's suppose my dataset in one CSV file is:

A B class
1 2  A
2 3  B
4 1  A
3 7  C
4 5  A
.....

Let's say 2nd CSVs dataset be:

A   B  class
10  20  A
20  10  C
40  10  B
30  17  A
14  15  A
.....

and so on for other CSVs..

Initially I have made ggplots for individual CSV files using "A" and "B". Now I want to plot all the CSV files in a single plot using only one class at a time i.e., Let's say I want to plot for only class A for all the CSVs in a single plot.

I did plot all the files in a single plot but now I want to plot it class wise..

Can any one tell how can I do this thing?

Upvotes: 0

Views: 333

Answers (1)

mathematical.coffee
mathematical.coffee

Reputation: 56915

Just join all your CSVs into one dataframe and subset and plot?

e.g.

csv1 <- read.csv(...)
csv2 <- read.csv(...)

bigcsv <- rbind(csv1, csv2)
library(ggplot2)

ggplot(subset(bigscv, class == 'A'), aes(...)) + ...

The key is simply to subset(bigcsv, class=='A').

You can also use rbind.fill to rbind a big list of dataframes.

Upvotes: 0

Related Questions