I have a dataset with the following variables: iso3 (country code), region, crude rate, age-standardized rate. Rates can be positive, negative or be equal to 0. Because the values are skewed towards one end for both crude and age-standardized rates, values need to be transformed.
I would like to do a scatter plot of transformed values of crude and age-standardized rates but keeping the x and y axis labels in real state space, using ggplot2. The dots would be colored depending on the region variable.
I have tried this:
pdf("Graphs/Scatter_Crude_ASDR.pdf")
scatter <- ggplot(df_scatter, aes(x = crude, y = agestd, color = region, label=iso3)) +
  geom_point(size = 2) +
  scale_x_continuous(trans=sign(crude) * log(abs(crude) + 1)) +
  scale_y_continuous(trans=sign(agestd) * log(abs(agestd) + 1)) +
  geom_text(hjust=-0.2, vjust=0, size=3) +
  geom_abline() +
  geom_hline(yintercept = 0) +
  labs(
    x="Crude rate",y="Age-standardized rate") +
  theme(
    plot.title = element_text(color = "#0099f9", size = 20, face = "bold", hjust = 0.5),
    plot.subtitle = element_text(size = 13, face = "bold", hjust = 0.5),
    plot.caption = element_text(face = "italic", hjust = 0)
  ) +
  guides(colour = guide_legend(title = "region"))
print(scatter)
dev.off()
R studio returns:
Error in is.trans(x) : object 'crude' not found
Here is a sample of my dataset:
# A tibble: 10 × 4
   iso3  region     crude         agestd
   <chr> <chr>      <dbl>          <dbl>
 1 AFG   EMRO        67.5         198.  
 2 AGO   AFRO        18.3          72.9 
 3 ALB   EURO       255.          134.  
 4 AND   EURO        93.9          55.1 
 5 ARE   EMRO        21.4          55.7 
 6 ARG   AMRO       139.          101.  
 7 ARM   EURO       354.          251.  
 8 ATG   AMRO       -38.8         -32.9 
 9 AUS   WPRO        12.2           1.22
10 AUT   EURO        98.9          36.6 
 
    