How can I adjust my heatmap so that it only shows the upper part?

# make an heatmap that only displays upper triangular of the correlation matrix
get_upper_tri <- function(data2){
  total[lower.tri(data2)]<- NA
  return(data2)
}

upper_tri <- get_upper_tri(data2)
#> Error in total[lower.tri(data2)] <- NA: object 'total' not found
upper_tri
#> Error in eval(expr, envir, enclos): object 'upper_tri' not found

library(reshape2)
melted_total <- melt(upper_tri, na.rm = TRUE)
#> Error in melt(upper_tri, na.rm = TRUE): object 'upper_tri' not found
library(ggplot2)
#> Registered S3 methods overwritten by 'ggplot2':
#>   method         from 
#>   [.quosures     rlang
#>   c.quosures     rlang
#>   print.quosures rlang
ggplot(data = upper_tri, aes(x= row, y=col, fill = corr))+
  geom_tile(color = "white")+
  scale_fill_gradient2(low = "blue", high = "red", mid = "white", 
                       midpoint = 0, limit = c(-1,1), space = "Lab", 
                       name="Pearson\nCorrelation") +
  theme_minimal()+ 
  theme(axis.text.x = element_text(angle = 45, vjust = 1, 
                                   size = 12, hjust = 1))+ labs( y="Variables", x="CpGs") +
  coord_fixed()
#> Error in ggplot(data = upper_tri, aes(x = row, y = col, fill = corr)): object 'upper_tri' not found

Created on 2019-06-06 by the reprex package (v0.3.0)