Different results apply geom_tile instead of heatmap












0















I am trying to apply geom_tile or heatmap indistinctly, but the results when I apply them are completely different.



I think that I understand why, I think that it is because the units for the different variable are different between them. So, while heatmap function understands that and only compares whit the same variable in the same column, geom_tile requires that all the variables including into the dataset will be expressed in the same unit.



1) Am I wrong with my assumption?
2) There is a way to use geom_tile and obtain the same result generated by heatmap?



Example using heatmap function:



library(ggplot2)
library(RColorBrewer)
library(readr)
url_soccer <- 'https://raw.githubusercontent.com/frm1789/soccer_ea/master/Example_Data_Matrix_heatmap.csv'

df_matrix <- read_csv(url_soccer)
# Order data for titles
df_matrix <- df_matrix[order(df_matrix$Titles, decreasing = FALSE),]
df_matrix <- data.frame(df_matrix)

#removing names of the teams.
row.names(df_matrix) <- df_matrix$Team
df_matrix <- df_matrix[,-1]

options(digits=2)
df_matrix$Points_1 <- sub(',', '.', df_matrix$Points_1)
df_matrix$Points_1 <- as.double(df_matrix$Points_1)

# transformation to numeric for column "Performance"
df_matrix$Performance =
substr(df_matrix$Performance,1,nchar(df_matrix$Performance)-1)
df_matrix$Performance <- sub(',', '.', df_matrix$Performance)
df_matrix$Performance <- as.double(df_matrix$Performance)
df_matrix$Performance <- log(df_matrix$Performance)

small_matrix <- data.matrix(df_matrix)

# Creation of heatmap
america_heatmap <- heatmap(small_matrix, Rowv=NA,
Colv=NA, col = brewer.pal(9, "Blues"),
scale="column",
margins=c(2,6))


Result using heatmap



Example using geom_tile function:



url_soccer 'https://raw.githubusercontent.com/frm1789/soccer_ea/master/Example_Data_format_ggplot_geom_tile.csv'

df_exa <- read_csv(url_soccer)
ggplot(data = df_exa, aes(x = df_exa$country, y = df_exa$metric)) +
geom_tile(aes(fill = df_exa$value)) +
coord_flip()+
theme_minimal()


Result obtained using geom_tile










share|improve this question























  • heatmap() does alot of the ordering for you. you have to do that deliberately in ggplot2

    – hrbrmstr
    Nov 24 '18 at 2:28











  • @hrbrmstr I didn't know that. But, Am I right about that heatmap let you compare different variables with different units and geom_tile requires an unique unit for all the dataset?

    – A89
    Nov 24 '18 at 5:29
















0















I am trying to apply geom_tile or heatmap indistinctly, but the results when I apply them are completely different.



I think that I understand why, I think that it is because the units for the different variable are different between them. So, while heatmap function understands that and only compares whit the same variable in the same column, geom_tile requires that all the variables including into the dataset will be expressed in the same unit.



1) Am I wrong with my assumption?
2) There is a way to use geom_tile and obtain the same result generated by heatmap?



Example using heatmap function:



library(ggplot2)
library(RColorBrewer)
library(readr)
url_soccer <- 'https://raw.githubusercontent.com/frm1789/soccer_ea/master/Example_Data_Matrix_heatmap.csv'

df_matrix <- read_csv(url_soccer)
# Order data for titles
df_matrix <- df_matrix[order(df_matrix$Titles, decreasing = FALSE),]
df_matrix <- data.frame(df_matrix)

#removing names of the teams.
row.names(df_matrix) <- df_matrix$Team
df_matrix <- df_matrix[,-1]

options(digits=2)
df_matrix$Points_1 <- sub(',', '.', df_matrix$Points_1)
df_matrix$Points_1 <- as.double(df_matrix$Points_1)

# transformation to numeric for column "Performance"
df_matrix$Performance =
substr(df_matrix$Performance,1,nchar(df_matrix$Performance)-1)
df_matrix$Performance <- sub(',', '.', df_matrix$Performance)
df_matrix$Performance <- as.double(df_matrix$Performance)
df_matrix$Performance <- log(df_matrix$Performance)

small_matrix <- data.matrix(df_matrix)

# Creation of heatmap
america_heatmap <- heatmap(small_matrix, Rowv=NA,
Colv=NA, col = brewer.pal(9, "Blues"),
scale="column",
margins=c(2,6))


Result using heatmap



Example using geom_tile function:



url_soccer 'https://raw.githubusercontent.com/frm1789/soccer_ea/master/Example_Data_format_ggplot_geom_tile.csv'

df_exa <- read_csv(url_soccer)
ggplot(data = df_exa, aes(x = df_exa$country, y = df_exa$metric)) +
geom_tile(aes(fill = df_exa$value)) +
coord_flip()+
theme_minimal()


Result obtained using geom_tile










share|improve this question























  • heatmap() does alot of the ordering for you. you have to do that deliberately in ggplot2

    – hrbrmstr
    Nov 24 '18 at 2:28











  • @hrbrmstr I didn't know that. But, Am I right about that heatmap let you compare different variables with different units and geom_tile requires an unique unit for all the dataset?

    – A89
    Nov 24 '18 at 5:29














0












0








0








I am trying to apply geom_tile or heatmap indistinctly, but the results when I apply them are completely different.



I think that I understand why, I think that it is because the units for the different variable are different between them. So, while heatmap function understands that and only compares whit the same variable in the same column, geom_tile requires that all the variables including into the dataset will be expressed in the same unit.



1) Am I wrong with my assumption?
2) There is a way to use geom_tile and obtain the same result generated by heatmap?



Example using heatmap function:



library(ggplot2)
library(RColorBrewer)
library(readr)
url_soccer <- 'https://raw.githubusercontent.com/frm1789/soccer_ea/master/Example_Data_Matrix_heatmap.csv'

df_matrix <- read_csv(url_soccer)
# Order data for titles
df_matrix <- df_matrix[order(df_matrix$Titles, decreasing = FALSE),]
df_matrix <- data.frame(df_matrix)

#removing names of the teams.
row.names(df_matrix) <- df_matrix$Team
df_matrix <- df_matrix[,-1]

options(digits=2)
df_matrix$Points_1 <- sub(',', '.', df_matrix$Points_1)
df_matrix$Points_1 <- as.double(df_matrix$Points_1)

# transformation to numeric for column "Performance"
df_matrix$Performance =
substr(df_matrix$Performance,1,nchar(df_matrix$Performance)-1)
df_matrix$Performance <- sub(',', '.', df_matrix$Performance)
df_matrix$Performance <- as.double(df_matrix$Performance)
df_matrix$Performance <- log(df_matrix$Performance)

small_matrix <- data.matrix(df_matrix)

# Creation of heatmap
america_heatmap <- heatmap(small_matrix, Rowv=NA,
Colv=NA, col = brewer.pal(9, "Blues"),
scale="column",
margins=c(2,6))


Result using heatmap



Example using geom_tile function:



url_soccer 'https://raw.githubusercontent.com/frm1789/soccer_ea/master/Example_Data_format_ggplot_geom_tile.csv'

df_exa <- read_csv(url_soccer)
ggplot(data = df_exa, aes(x = df_exa$country, y = df_exa$metric)) +
geom_tile(aes(fill = df_exa$value)) +
coord_flip()+
theme_minimal()


Result obtained using geom_tile










share|improve this question














I am trying to apply geom_tile or heatmap indistinctly, but the results when I apply them are completely different.



I think that I understand why, I think that it is because the units for the different variable are different between them. So, while heatmap function understands that and only compares whit the same variable in the same column, geom_tile requires that all the variables including into the dataset will be expressed in the same unit.



1) Am I wrong with my assumption?
2) There is a way to use geom_tile and obtain the same result generated by heatmap?



Example using heatmap function:



library(ggplot2)
library(RColorBrewer)
library(readr)
url_soccer <- 'https://raw.githubusercontent.com/frm1789/soccer_ea/master/Example_Data_Matrix_heatmap.csv'

df_matrix <- read_csv(url_soccer)
# Order data for titles
df_matrix <- df_matrix[order(df_matrix$Titles, decreasing = FALSE),]
df_matrix <- data.frame(df_matrix)

#removing names of the teams.
row.names(df_matrix) <- df_matrix$Team
df_matrix <- df_matrix[,-1]

options(digits=2)
df_matrix$Points_1 <- sub(',', '.', df_matrix$Points_1)
df_matrix$Points_1 <- as.double(df_matrix$Points_1)

# transformation to numeric for column "Performance"
df_matrix$Performance =
substr(df_matrix$Performance,1,nchar(df_matrix$Performance)-1)
df_matrix$Performance <- sub(',', '.', df_matrix$Performance)
df_matrix$Performance <- as.double(df_matrix$Performance)
df_matrix$Performance <- log(df_matrix$Performance)

small_matrix <- data.matrix(df_matrix)

# Creation of heatmap
america_heatmap <- heatmap(small_matrix, Rowv=NA,
Colv=NA, col = brewer.pal(9, "Blues"),
scale="column",
margins=c(2,6))


Result using heatmap



Example using geom_tile function:



url_soccer 'https://raw.githubusercontent.com/frm1789/soccer_ea/master/Example_Data_format_ggplot_geom_tile.csv'

df_exa <- read_csv(url_soccer)
ggplot(data = df_exa, aes(x = df_exa$country, y = df_exa$metric)) +
geom_tile(aes(fill = df_exa$value)) +
coord_flip()+
theme_minimal()


Result obtained using geom_tile







r ggplot2 heatmap






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 0:49









A89A89

246




246













  • heatmap() does alot of the ordering for you. you have to do that deliberately in ggplot2

    – hrbrmstr
    Nov 24 '18 at 2:28











  • @hrbrmstr I didn't know that. But, Am I right about that heatmap let you compare different variables with different units and geom_tile requires an unique unit for all the dataset?

    – A89
    Nov 24 '18 at 5:29



















  • heatmap() does alot of the ordering for you. you have to do that deliberately in ggplot2

    – hrbrmstr
    Nov 24 '18 at 2:28











  • @hrbrmstr I didn't know that. But, Am I right about that heatmap let you compare different variables with different units and geom_tile requires an unique unit for all the dataset?

    – A89
    Nov 24 '18 at 5:29

















heatmap() does alot of the ordering for you. you have to do that deliberately in ggplot2

– hrbrmstr
Nov 24 '18 at 2:28





heatmap() does alot of the ordering for you. you have to do that deliberately in ggplot2

– hrbrmstr
Nov 24 '18 at 2:28













@hrbrmstr I didn't know that. But, Am I right about that heatmap let you compare different variables with different units and geom_tile requires an unique unit for all the dataset?

– A89
Nov 24 '18 at 5:29





@hrbrmstr I didn't know that. But, Am I right about that heatmap let you compare different variables with different units and geom_tile requires an unique unit for all the dataset?

– A89
Nov 24 '18 at 5:29












1 Answer
1






active

oldest

votes


















0














Point 1) The initial assumption is correct.



In this example, for this dataset, it is not posible to use geom_tile, because the way that geom_tile works is to divide all the data into smaller rectangles or squares. Each of the smaller rectangles is called a tile. There is no parameter to consider different scales, for columns or rows, because geom_tile assumes all the dataset is expressed in the same unit.



In this example we have variables expressed in different units like goals, performance, points, and there is no relationship between them.



On the other hand, heatmap allow you to use the parameter "scale", and for this case we are using scale= "column", indicating that the values should be scaled for each column.



Point 2)
There is a way to do that:
Heat map per column with ggplot2






share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454275%2fdifferent-results-apply-geom-tile-instead-of-heatmap%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Point 1) The initial assumption is correct.



    In this example, for this dataset, it is not posible to use geom_tile, because the way that geom_tile works is to divide all the data into smaller rectangles or squares. Each of the smaller rectangles is called a tile. There is no parameter to consider different scales, for columns or rows, because geom_tile assumes all the dataset is expressed in the same unit.



    In this example we have variables expressed in different units like goals, performance, points, and there is no relationship between them.



    On the other hand, heatmap allow you to use the parameter "scale", and for this case we are using scale= "column", indicating that the values should be scaled for each column.



    Point 2)
    There is a way to do that:
    Heat map per column with ggplot2






    share|improve this answer






























      0














      Point 1) The initial assumption is correct.



      In this example, for this dataset, it is not posible to use geom_tile, because the way that geom_tile works is to divide all the data into smaller rectangles or squares. Each of the smaller rectangles is called a tile. There is no parameter to consider different scales, for columns or rows, because geom_tile assumes all the dataset is expressed in the same unit.



      In this example we have variables expressed in different units like goals, performance, points, and there is no relationship between them.



      On the other hand, heatmap allow you to use the parameter "scale", and for this case we are using scale= "column", indicating that the values should be scaled for each column.



      Point 2)
      There is a way to do that:
      Heat map per column with ggplot2






      share|improve this answer




























        0












        0








        0







        Point 1) The initial assumption is correct.



        In this example, for this dataset, it is not posible to use geom_tile, because the way that geom_tile works is to divide all the data into smaller rectangles or squares. Each of the smaller rectangles is called a tile. There is no parameter to consider different scales, for columns or rows, because geom_tile assumes all the dataset is expressed in the same unit.



        In this example we have variables expressed in different units like goals, performance, points, and there is no relationship between them.



        On the other hand, heatmap allow you to use the parameter "scale", and for this case we are using scale= "column", indicating that the values should be scaled for each column.



        Point 2)
        There is a way to do that:
        Heat map per column with ggplot2






        share|improve this answer















        Point 1) The initial assumption is correct.



        In this example, for this dataset, it is not posible to use geom_tile, because the way that geom_tile works is to divide all the data into smaller rectangles or squares. Each of the smaller rectangles is called a tile. There is no parameter to consider different scales, for columns or rows, because geom_tile assumes all the dataset is expressed in the same unit.



        In this example we have variables expressed in different units like goals, performance, points, and there is no relationship between them.



        On the other hand, heatmap allow you to use the parameter "scale", and for this case we are using scale= "column", indicating that the values should be scaled for each column.



        Point 2)
        There is a way to do that:
        Heat map per column with ggplot2







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 26 '18 at 1:13

























        answered Nov 26 '18 at 0:34









        A89A89

        246




        246
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53454275%2fdifferent-results-apply-geom-tile-instead-of-heatmap%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'