# How to use the image function in R

**Data Science Tutorials**, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

The post How to use the image function in R appeared first on Data Science Tutorials

What do you have to lose?. Check out Data Science tutorials here Data Science Tutorials.

`How to use the image function in R`

, When displaying spatial data (pictures), the image function can be used to generate a grid of coloured rectangles based on the values of the z matrix.

The grid on which the values of z are measured can be specified using the variables x and y.

ggdogs on ggplot2 – Data Science Tutorials

# Data x <- -10:10 y <- -10:10 z <- sqrt(outer(x ^ 2, y ^ 2, "+")) image(x, y, z) # You can also type, the following # but the axes will be between 0 and 1 image(z)

How to perform the Kruskal-Wallis test in R? – Data Science Tutorials

**Color customization**

The image’s colour scheme can be altered with the col argument. A function like gray.colors, topo.colors, hcl.colors, or a related function can be passed as a variable. hcl.colors(12, “YlOrRd”, rev = TRUE) is the default value.

image(x, y, z, col = gray.colors(12))

Keep in mind that the colour image will become smoother as you increase the amount of values.

**Overlaying a contour**

By supplying the same data to the function and specifying add = TRUE, it is feasible to overlay the contour lines over the colour image.

Best Books on Data Science with Python – Data Science Tutorials

image(x, y, z) contour(x, y, z, add = TRUE)

How to Use “not in” operator in Filter – Data Science Tutorials

The post How to use the image function in R appeared first on Data Science Tutorials

Learn how to expert in the Data Science field with Data Science Tutorials.

**leave a comment**for the author, please follow the link and comment on their blog:

**Data Science Tutorials**.

R-bloggers.com offers

**daily e-mail updates**about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.

Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.