title: ggplot2 grouped barchart with 2 datasets
body: <p>I have 2 data.frames that I want to plot together with a grouped barchart.</p>
  
  <p>The first dataframe is a stacked barchart with multiple colors and a corresponding axis on the left.</p>
  
  <p>The second dataframe is a single barchart with one color only and the corresponding axis on the right.</p>
  
  <p>The image below illustrates my goal:</p>
  
  <p><a href="https://i.stack.imgur.com/foNmQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/foNmQ.png" alt="enter image description here"></a></p>
  
  <p>Here is my dataset and my failing attempt:</p>
  
  <pre><code>library(ggplot2)
  library(dplyr)
  df1 &lt;- structure(list(day = structure(c(1L, 1L, 1L, 1L), .Label = "2019-01-29", class = "factor"), 
                        streckenabschn = c("something", "something", "something", "something"), 
                        variable = c("a", "b", "c", "d"), 
                        value = c(0, 0, 2, 8)), 
                   row.names = c(NA, -4L), class = "data.frame")
  
  df2 &lt;- structure(list(day = structure(1:2, .Label = c("2015-12-25", "2019-01-29"), class = "factor"), 
                        streckenabschn = c("something", "something"), 
                        variable = c("x", "x"), value = c(0.6, 3.471875)), 
                   row.names = 1:2, class = "data.frame")
  
  
  cbPalette &lt;- c('#3652a3', '#60a0df', '#b7dbff', '#dd0000', "gray")
  legendLabels &lt;- c("a", "b", "c", "d", "x")
  ggplot() +
    geom_bar(data = df1, aes(x=day, y=value, fill = variable),
             stat = "identity", width=0.2) +
    geom_bar(data = df2, aes(x=day, y=value, fill = variable),
             stat = "identity", width=0.2, position = position_dodge(width=0.5)) +
    scale_fill_manual(name="", values=cbPalette, labels=legendLabels) +
    scale_y_continuous(sec.axis = sec_axis(~., name = "Axis 2")) +
    guides(fill = guide_legend("Legend", nrow = 2, ncol=4, byrow = T)) +
    theme(legend.position = "top") + ylab("Axis 1")
  </code></pre>
  
  <p><strong>My Problems:</strong>   </p>
  
  <ul>
  <li>How can I have 1 barchart that is stacked, while the other one is
  "dodged"?    </li>
  <li>How can I define the "Axis 2" labels and breaks to
  correspond to the data, since I cannot use a transformation formula?</li>
  </ul>
  
  <p>What am I doing wrong and how to do it right?</p>