I am trying to make a graph with the mean of trash collected of the multiple data sets but unsuccessful .

Trash collected dump truck shif 1,mapa 1,2,3

DUMPT1_1 <- filter(data8,TC %in% "DUMPT",shift2 %in% "1",MAP %in% "1")#turno1 , mapa1
DUMPT1_2 <- filter(data8,TC %in% "DUMPT",shift2 %in% "1",MAP %in% "2")#turno1 , mapa2
DUMPT1_3 <- filter(data8,TC %in% "DUMPT",shift2 %in% "1",MAP %in% "3")#turno1 , mapa3
#trash collected dump truck second shift 2 mapa 1,2,3
DUMPT2_1 <- filter(data8,TC %in% "DUMPT",shift2 %in% "2",MAP %in% "1")#turno 2 mapa 1
DUMPT2_2 <- filter(data8,TC %in% "DUMPT",shift2 %in% "2",MAP %in% "2")#turnoc2 mapa 2
DUMPT2_3 <- filter(data8,TC %in% "DUMPT",shift2 %in% "2",MAP %in% "3")#turno2 mapa 3

##trash collected compact truck shift 2,map 1,2,3
##turno 1 y dos para el compact truck .
COMPACT1_1 <- filter(data8,TC %in% "COMPACTT",shift2 %in% "1",MAP %in%"1")#turno 2 mapa 1
COMPACT1_2 <- filter(data8,TC %in% "COMPACTT",shift2 %in% "1",MAP %in% "2")#turno 2 mapa 2
COMPACT1_3 <- filter(data8,TC %in% "COMPACTT",shift2 %in% "1",MAP %in% "3")#turno 2 mapa 3

###COMPACT ##shift 2
COMPACT2_1 <- filter(data8,TC %in% "COMPACTT",shift2 %in% "2",MAP %in%"1")#turno 2
COMPACT2_2 <- filter(data8,TC %in% "COMPACTT",shift2 %in% "2",MAP %in%"2")
COMPACT2_3 <- filter(data8,TC %in% "COMPACTT",shift2 %in% "2",MAP %in%"3")

Mean of the Trash collected of file DUMPT_1...., AND COMPACT_1...

Trash_Collected_1 c(mean(DUMPT1_1$amount_of_thrash_collected),mean(DUMPT1_2$amount_of_thrash_collected),mean(DUMPT1_3$amount_of_thrash_collected))
Trash_Collected_2 <- c(mean(COMPACT1_1$amount_of_thrash_collected),mean(COMPACT1_2$amount_of_thrash_collected),mean(COMPACT1_3$amount_of_thrash_collected))

ggplot()+
geom_line(aes(c(5,6,7),Trash_Collected_1,colour= TC ))+
geom_point(aes(c(5,6,7),Trash_Collected_1,colour=TC))+
geom_line(aes(c(5,6,7),Trash_Collected_2,colour=TC))+
geom_point(aes(c(5,6,7),Trash_Collected_2,colour=TC))+

xlab("tons")+ylab("trash Collected")

I ge this error Error in `geom_line()`:
! Problem while computing aesthetics.
ℹ Error occurred in the 1st layer.
Caused by error in `FUN()`:
! object 'TC' not found

but TC is in the data set DUMPT AND COMPACT

I think we need see moreyour code and some sample data.

A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where mydata is your data. Copy the output and paste it here.

I recommend you back to basics and consider some simple ggplot2 examples. Ggplot2 needs a data= argument. You seem to be adding data.frames as entries in you aes statements. This is not how one uses ggplot2.

Hi @MALVIS
You seem to be trying to make multiple subsets of your main dataframe. You can use group_by() to achieve this, then calculate the means, save the results, and plot as a histogram with ggplot().
Something like this might work (but as stated above, we don't have access to a sample of your data):

data8 |> 
  group_by(TC, shift2, MAP) |> 
  summarise(m_amount = mean(amount_of_thrash_collected, na.rm=TRUE)) -> means_df

ggplot(means_df) +
  aes(y=m_amount) +
  geom_histogram()

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.