---
title: "Adapt secondary axis with sec_axis() in ggplot2"
description: "I'm struggling a bit to get the secondary axis the way I want. Here is the data: structure(list(date = structure(c(19723, 19724, 19725, 19726, 19727, 19728, 19729, 19730, 19731, 19732, 19733, 19734,..."
url: https://extraproxies.com/adapt-secondary-axis-with-sec_axis-in-ggplot2
date: 2024-02-13
modified: 2024-02-13
author: "ExtraProxies"
categories: ["Proxy News"]
tags: ["Adapt", "axis", "ggplot2", "secondary", "sec_axis"]
type: post
lang: en
---

# Adapt secondary axis with sec_axis() in ggplot2

I’m struggling a bit to get the secondary axis the way I want.

Here is the data:

```
structure(list(date = structure(c(19723, 19724, 19725, 19726,  19727, 19728, 19729, 19730, 19731, 19732, 19733, 19734, 19735,  19736, 19737, 19738, 19739, 19740, 19741, 19742, 19743, 19744,  19745, 19746, 19747, 19748, 19749, 19750, 19751, 19752, 19753,  19754, 19755, 19756, 19757, 19758, 19759, 19760, 19761, 19762,  19763, 19764, 19765), class = "Date"), tmin = c(3.8, 2.8, 8.1,  8.2, 4.6, 3.6, 1.8, -0.8, 4.1, 4.7, 2.3, -0.4, 2.2, 5.8, 8.4,  11.1, 10, 10, 3.6, 2.7, 4, 3.1, 4.4, 5.9, 5.9, 5.9, 9.6, 8, 7.7,  5.9, 4.7, 4.6, 5.2, 5.9, 4.6, 4.6, 5.9, NA, 8.5, 7.9, 5.3, 4.3,  6), tmax = c(9.4, 8.2, 12.1, 10.6, 8.6, 9.6, 9.3, 6.2, 7.2, 8,  7.6, 6.9, 9, 8.6, 13.3, 13.7, 12.3, 14.3, 10.8, 9.9, 11, 10.6,  14.9, 17.5, 17.3, 18.8, 18, 16.3, 14.9, 13, 10.5, 16.8, 14.8,  15.2, 16.6, 14.9, 13.7, NA, 12.6, 11.7, 11.3, 8.3, 15.7), tmean = c(6.6,  5.5, 10.1, 9.4, 6.6, 6.6, 5.6, 2.7, 5.6, 6.4, 5, 3.2, 5.6, 7.2,  10.8, 12.4, 11.2, 12.2, 7.2, 6.3, 7.5, 6.8, 9.6, 11.7, 11.6,  12.4, 13.8, 12.2, 11.3, 9.4, 7.6, 10.7, 10, 10.6, 10.6, 9.8,  9.8, NA, 10.6, 9.8, 8.3, 6.3, 10.8), pcp = c(NA, 2, 2.7, 9.7,  0.1, NA, NA, NA, NA, 0.2, NA, NA, NA, 4.3, 2.6, 7.5, 1.1, 12.4,  16.3, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,  NA, NA, NA, NA, NA, 6.2, 6.5, 0.4, 0.1, NA)), row.names = c(NA,  -43L), class = c("tbl_df", "tbl", "data.frame"))
```

And here is my code so far:

```
selected_year
