Create a graphic of the data

We are using the ggplot function from the ggploe2 library to plot the graph of the given dataframe. Here, we are just visualizing the data frame accordingly in the R programming language.

R




library("ggplot2")             
new_df <- ggplot(df,          
              aes(x, y, fill = z)) +
  geom_tile()
new_df


Output:

 

Scale ggplot2 Color Gradient to Range Outside of Data in R

In this article, we are going to see how to Scale ggplot2 Color Gradient to Range Outside of Data in R Programming Language.

Creating dataframe:

Under this, we are simply creating a data frame of 6 rows and 3 columns.

R




df <- data.frame(x = seq(- 2, 2, 1),
                   y = rep(seq(- 2, 2, 1), each = 5),
                   z = round(rnorm(25, 50, 70)))
head(df)


Output:

 

Similar Reads

Create a graphic of the data

...

Specify Colors, Limits & Breaks Using scale_fill_gradient() Function:

We are using the ggplot function from the ggploe2 library to plot the graph of the given dataframe. Here, we are just visualizing the data frame accordingly in the R programming language....