Error in check_aesthetics: Aesthetics must be either length 1 or the same as the data (240): y.

p3 <- ggplot(uebersicht_jahre.df, aes(x=Jahre)) +

geom_bar(aes(y=Jahr_avM_W), stat = "identity", size=1, fill='skyblue')+

geom_line(aes(y=Jahr_sum_N, group=1), size=1, color="darkblue")+

scale_x_discrete(breaks = c("1999", "2005", "2010", "2015", "2018")) +

scale_y_continuous(name="Oberflaechenwasserstand [cm]", sec.axis = sec_axis(~./1,name="Niederschlag [mm]"))+

labs(x="Jahre", tag = "d") +

theme(axis.title = element_text(size = 10),

axis.text = element_text(size=8),

panel.grid = element_blank(),

plot.title = element_text(size=12, face = 'bold'))  

p4 <- ggplot(uebersicht_jahre.df, aes(x=Jahre)) +

geom_bar(aes(y=Jahr_avM_W), stat = "identity", size=0.1, fill='skyblue')+

geom_line(aes(y=Jahr_avM_Wetter, group=1), size=1, color="red")+

scale_x_discrete(breaks = c("1999", "2005", "2010", "2015", "2018")) +

scale_y_continuous(name="Oberflaechenwasserstand [cm]", sec.axis = sec_axis(~./1,name="Temperatur [C°]")) +

labs(x="Jahre", tag = "d") +

theme(axis.title = element_text(size = 10),

axis.text = element_text(size=8),

panel.grid = element_blank(),

plot.title = element_text(size=12, face = 'bold')) 

jpeg(filename = "ggplot.jpeg",width = 1000, height = 1000)

grid.arrange(p3, p4, nrow=2)

dev.off()

Error shows:
Error in check_aesthetics():

! Aesthetics must be either length 1 or the same as the data (240): y

Run rlang::last_error() to see where the error occurred.

Thank you for every answer to solve the Problem.

I do not see an obvious problem with your code but it is hard to be sure without having your data. Please post some of your data. A simpe way to do that is to post the output of

dput(head(uebersicht_jahre.df, 30))

Place a line with three back ticks just before and after the output that you post, like this
```
Output of dput()
```

structure(list(Jahre = c("1999", "2000", "2001", "2002", "2003", 
"2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", 
"2012", "2013", "2014", "2015", "2016", "2017", "2018"), Niederschlagssumme = c(697.4, 
530.4, 561.4, 798.101, 484, 732.001, 604.1, 668, 826.901, 640.9, 
899.6, 873, 535.5, 591.202, 703.8, 753.1, 524, 679.3, 546.801, 
609.8), Temperaturmittelwert = c(127.9, 140.3, 126.9, 135.8, 
131.4, 125.4, 122.6, 128.2, 139.8, 137.1, 132, 118.8, 132.6, 
135.4, 130.3, 143.6, 144.8, 138.1, 139.1, 148.9), Grundwasserstand_Mittelwert = c(1931.78, 
1932.39, 1771.23, 1934.48, 1929.74, 1930.84, 1931.47, 1932.33, 
1931.19, 1931.55, 1933.76, 1935.39, 1934.17, 1934.86, 1934.78, 
1931.78, 1931.16, 1931.94, 1931.93, 1931.19), Oberflächenwasserstand_Mittelwert = c(1682.50760368664, 
1640.69202817946, 1606.86351766513, 1675.3168202765, 1640.68102918587, 
1661.81568409344, 1645.37741935484, 1679.72357910906, 1664.12749615975, 
1687.59536522062, 1716.81351766513, 1722.55453149002, 1666.10967741935, 
1632.59747868001, 1692.80268817204, 1655.99470046083, 1675.55983102919, 
1680.24241750093, 1655.24569892473, 1650.37265745008)), row.names = c(NA, 
20L), class = "data.frame")

Also it seems like the problem is within these two lines:
geom_bar(aes(y=Jahr_avM_W), stat = "identity", size=1, fill='skyblue')+

geom_line(aes(y=Jahr_sum_N, group=1), size=1, color="darkblue")+

The data you posted has the the following column names

colnames(uebersicht_jahre.df)
[1] "Jahre"                            
[2] "Niederschlagssumme"               
[3] "Temperaturmittelwert"             
[4] "Grundwasserstand_Mittelwert"      
[5] "Oberflächenwasserstand_Mittelwert"

In your ggplot code, you try to use Jahr_avM_W and Jahr_sum_N as y values. Are those produced elsewhere in your code? Do they have the same length as the number of rows in uebersicht_jahre.df?

Thank you so much!! I forgott i changed the names .

This topic was automatically closed 7 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.