How to set different color scales for hexbin based on data groups?Different colors with gradient for subgroups on a treemap ggplot2 Rgeom_tile different gradient scale and color for different factorsManual fill geom_tile with multiple scales by groupCombine continuous and discrete color scale in ggplot2?hexbin data aggregation with color and size attributesdata.table vs dplyr: can one do something well the other can't or does poorly?How to create different colours for the same group between geom_smooth and geom_point?Color data points based on sample classificationR - How to set the range of the colorscale in a hexbin plotGive color to scatter plot points based on value thersholdchange color data points plotLearnerPrediction (MLR package)Coloring nodes of a graph according to the different scalesR - Compare two hexbin plots with different sizes after normalization

Opposite of "Squeaky wheel gets the grease"

Setting extra bits in a bool makes it true and false at the same time

Word for a small burst of laughter that can't be held back

Why does a helium balloon rise?

Why is Colorado so different politically from nearby states?

Is there a practical difference between different types of Berachos?

Anyone teach web development? How do you assess it?

Is the decompression of compressed and encrypted data without decryption also theoretically impossible?

Can you please explain this joke: "I'm going bananas is what I tell my bananas before I leave the house"?

Restoring order in a deck of playing cards (II)

Is it possible for people to live in the eye of a permanent hypercane?

Is it legal in the UK for politicians to lie to the public for political gain?

If a problem only occurs randomly once in every N times on average, how many tests do I have to perform to be certain that it's now fixed?

Show sparse matrices like chessboards

Rotated Position of Integers

Is the capacitor drawn or wired wrongly?

Explain Ant-Man's "not it" scene from Avengers: Endgame

Short story written from alien perspective with this line: "It's too bright to look at, so they don't"

California: "For quality assurance, this phone call is being recorded"

Are there practical reasons to NOT use a stepper motor with lead screw for the X and or Y axes?

Is having a hidden directory under /etc safe?

Applicants clearly not having the skills they advertise

Computing the differentials in the Adams spectral sequence

Can an old DSLR be upgraded to match modern smartphone image quality



How to set different color scales for hexbin based on data groups?


Different colors with gradient for subgroups on a treemap ggplot2 Rgeom_tile different gradient scale and color for different factorsManual fill geom_tile with multiple scales by groupCombine continuous and discrete color scale in ggplot2?hexbin data aggregation with color and size attributesdata.table vs dplyr: can one do something well the other can't or does poorly?How to create different colours for the same group between geom_smooth and geom_point?Color data points based on sample classificationR - How to set the range of the colorscale in a hexbin plotGive color to scatter plot points based on value thersholdchange color data points plotLearnerPrediction (MLR package)Coloring nodes of a graph according to the different scalesR - Compare two hexbin plots with different sizes after normalization






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I'm generating scatter plot of the comparison of 2 variables in a data frame, where the colors of the points were determined by their type (another column in the data frame). However, there are many points that overlap each other and therefore I want an estimation of how many points there are in a given part of the grid. (for example: In case of hexbin package, one can estimate how many values there are in a given hexagon on the grid)



My question is: how can I use the hexbin package where for every group I will have another color scale, so in that way it will be possible to distinguish between the groups and get an evaluation of how many values there are.



I tried to google it but didn't find any satisfying solution.
All the options that I found were focused only on the distinction between the groups.



My code so far:



ggplot(data_for_scatter_plot,aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type))) +
geom_point(alpha = 0.6)


where my data_for_scatter_plot data frame is:



 Gene Log2FoldChange length TT_frequency Type
ENSG00000007968 1.928153 24791 0.05623008 up_regulated
ENSG00000009724 2.209263 20711 0.05842306 down_regulated
ENSG00000010219 1.794972 53099 0.08250626 other_genes
ENSG00000053438 3.815411 2479 0.10851150 up_regulated


And the graph that I get is:



scatterplot



While I want to get the following graph for each group in a different color scale:



hexbin plot










share|improve this question
























  • Short answer is no, you can only use one scale per aesthetic (such as fill). Longer answer is folks have done some workarounds before, often by using opacity to mimic lighten gradients. Here are a couple: stackoverflow.com/q/46333719/5325862, stackoverflow.com/q/55167464/5325862

    – camille
    Mar 24 at 15:38











  • Here's another one with several ideas: stackoverflow.com/q/50163072/5325862

    – camille
    Mar 24 at 16:03

















0















I'm generating scatter plot of the comparison of 2 variables in a data frame, where the colors of the points were determined by their type (another column in the data frame). However, there are many points that overlap each other and therefore I want an estimation of how many points there are in a given part of the grid. (for example: In case of hexbin package, one can estimate how many values there are in a given hexagon on the grid)



My question is: how can I use the hexbin package where for every group I will have another color scale, so in that way it will be possible to distinguish between the groups and get an evaluation of how many values there are.



I tried to google it but didn't find any satisfying solution.
All the options that I found were focused only on the distinction between the groups.



My code so far:



ggplot(data_for_scatter_plot,aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type))) +
geom_point(alpha = 0.6)


where my data_for_scatter_plot data frame is:



 Gene Log2FoldChange length TT_frequency Type
ENSG00000007968 1.928153 24791 0.05623008 up_regulated
ENSG00000009724 2.209263 20711 0.05842306 down_regulated
ENSG00000010219 1.794972 53099 0.08250626 other_genes
ENSG00000053438 3.815411 2479 0.10851150 up_regulated


And the graph that I get is:



scatterplot



While I want to get the following graph for each group in a different color scale:



hexbin plot










share|improve this question
























  • Short answer is no, you can only use one scale per aesthetic (such as fill). Longer answer is folks have done some workarounds before, often by using opacity to mimic lighten gradients. Here are a couple: stackoverflow.com/q/46333719/5325862, stackoverflow.com/q/55167464/5325862

    – camille
    Mar 24 at 15:38











  • Here's another one with several ideas: stackoverflow.com/q/50163072/5325862

    – camille
    Mar 24 at 16:03













0












0








0








I'm generating scatter plot of the comparison of 2 variables in a data frame, where the colors of the points were determined by their type (another column in the data frame). However, there are many points that overlap each other and therefore I want an estimation of how many points there are in a given part of the grid. (for example: In case of hexbin package, one can estimate how many values there are in a given hexagon on the grid)



My question is: how can I use the hexbin package where for every group I will have another color scale, so in that way it will be possible to distinguish between the groups and get an evaluation of how many values there are.



I tried to google it but didn't find any satisfying solution.
All the options that I found were focused only on the distinction between the groups.



My code so far:



ggplot(data_for_scatter_plot,aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type))) +
geom_point(alpha = 0.6)


where my data_for_scatter_plot data frame is:



 Gene Log2FoldChange length TT_frequency Type
ENSG00000007968 1.928153 24791 0.05623008 up_regulated
ENSG00000009724 2.209263 20711 0.05842306 down_regulated
ENSG00000010219 1.794972 53099 0.08250626 other_genes
ENSG00000053438 3.815411 2479 0.10851150 up_regulated


And the graph that I get is:



scatterplot



While I want to get the following graph for each group in a different color scale:



hexbin plot










share|improve this question
















I'm generating scatter plot of the comparison of 2 variables in a data frame, where the colors of the points were determined by their type (another column in the data frame). However, there are many points that overlap each other and therefore I want an estimation of how many points there are in a given part of the grid. (for example: In case of hexbin package, one can estimate how many values there are in a given hexagon on the grid)



My question is: how can I use the hexbin package where for every group I will have another color scale, so in that way it will be possible to distinguish between the groups and get an evaluation of how many values there are.



I tried to google it but didn't find any satisfying solution.
All the options that I found were focused only on the distinction between the groups.



My code so far:



ggplot(data_for_scatter_plot,aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type))) +
geom_point(alpha = 0.6)


where my data_for_scatter_plot data frame is:



 Gene Log2FoldChange length TT_frequency Type
ENSG00000007968 1.928153 24791 0.05623008 up_regulated
ENSG00000009724 2.209263 20711 0.05842306 down_regulated
ENSG00000010219 1.794972 53099 0.08250626 other_genes
ENSG00000053438 3.815411 2479 0.10851150 up_regulated


And the graph that I get is:



scatterplot



While I want to get the following graph for each group in a different color scale:



hexbin plot







r ggplot2 overlap






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 24 at 15:28









camille

9,08751935




9,08751935










asked Mar 24 at 12:30









ElizabethElizabeth

7410




7410












  • Short answer is no, you can only use one scale per aesthetic (such as fill). Longer answer is folks have done some workarounds before, often by using opacity to mimic lighten gradients. Here are a couple: stackoverflow.com/q/46333719/5325862, stackoverflow.com/q/55167464/5325862

    – camille
    Mar 24 at 15:38











  • Here's another one with several ideas: stackoverflow.com/q/50163072/5325862

    – camille
    Mar 24 at 16:03

















  • Short answer is no, you can only use one scale per aesthetic (such as fill). Longer answer is folks have done some workarounds before, often by using opacity to mimic lighten gradients. Here are a couple: stackoverflow.com/q/46333719/5325862, stackoverflow.com/q/55167464/5325862

    – camille
    Mar 24 at 15:38











  • Here's another one with several ideas: stackoverflow.com/q/50163072/5325862

    – camille
    Mar 24 at 16:03
















Short answer is no, you can only use one scale per aesthetic (such as fill). Longer answer is folks have done some workarounds before, often by using opacity to mimic lighten gradients. Here are a couple: stackoverflow.com/q/46333719/5325862, stackoverflow.com/q/55167464/5325862

– camille
Mar 24 at 15:38





Short answer is no, you can only use one scale per aesthetic (such as fill). Longer answer is folks have done some workarounds before, often by using opacity to mimic lighten gradients. Here are a couple: stackoverflow.com/q/46333719/5325862, stackoverflow.com/q/55167464/5325862

– camille
Mar 24 at 15:38













Here's another one with several ideas: stackoverflow.com/q/50163072/5325862

– camille
Mar 24 at 16:03





Here's another one with several ideas: stackoverflow.com/q/50163072/5325862

– camille
Mar 24 at 16:03












1 Answer
1






active

oldest

votes


















0














While this is not exactly what you asked for it might be a push in the right direction.



I don't think multiple color/cont scales are possible at the same time. You can change the color of the lines around the hexes, and increase line thickness.



First some sample data (please provide this yourself in the future)



library(tidyverse)
library(hexbin)

set.seed(1)

data_for_scatter_plot <-
crossing(
tibble(Trial =seq(1:100)),
tibble(Extra = seq(1:10)),
tribble(
~Gene, ~Log2FoldChange, ~length, ~TT_frequency, ~Type,
"ENSG00000007968", 1.928153, 24791, 0.05623008, "up_regulated",
"ENSG00000009724", 2.209263, 20711, 0.05842306, "down_regulated",
"ENSG00000010219", 1.794972, 53099, 0.08250626, "other_genes",
"ENSG00000053438", 3.815411, 2479 , 0.10851150, "up_regulate")) %>%
mutate(
Log2FoldChange = Log2FoldChange*0.001*Trial+rnorm(n=n(), mean=0, sd = 0.1),
TT_frequency = TT_frequency-0.00001*Trial+rnorm(n=n(), mean=0, sd = 0.005)
)


data_for_scatter_plot

# A tibble: 4,000 x 7
Trial Extra Gene Log2FoldChange length TT_frequency Type
<int> <int> <chr> <dbl> <dbl> <dbl> <chr>
1 1 1 ENSG00000007968 -0.0607 24791 0.0505 up_regulated
2 1 1 ENSG00000009724 0.0206 20711 0.0622 down_regulated
3 1 1 ENSG00000010219 -0.0818 53099 0.0853 other_genes
4 1 1 ENSG00000053438 0.163 2479 0.102 up_regulate
5 1 2 ENSG00000007968 0.0349 24791 0.0461 up_regulated
6 1 2 ENSG00000009724 -0.0798 20711 0.0614 down_regulated
7 1 2 ENSG00000010219 0.0505 53099 0.0754 other_genes
8 1 2 ENSG00000053438 0.0776 2479 0.117 up_regulate
9 1 3 ENSG00000007968 0.0595 24791 0.0654 up_regulated
10 1 3 ENSG00000009724 -0.0283 20711 0.0653 down_regulated
# ... with 3,990 more rows


Now the plot:



data_for_scatter_plot %>% 
ggplot(aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type)))+
geom_hex(size = 1)


enter image description here



I hope this helps.



---EDIT after comment---

I think a better solution for you is to facet. This will also make you able to distinguish overlapping groups



data_for_scatter_plot %>% 
ggplot(aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type)))+
geom_hex()+
facet_grid(cols = vars(factor(Type)))


enter image description here






share|improve this answer

























  • Thank you, I already use this solution, but I'm looking for more "looking good" one.

    – Elizabeth
    Mar 24 at 13:42











  • I don't think that wish is possible with geom_hex(). Is it important for you that it is geom_hex(), or have you already considered options such as faceting, fill, alpha?

    – Steen Harsted
    Mar 24 at 13:59











  • It's not important to me which package to use as long as I get the results that I want.

    – Elizabeth
    Mar 24 at 14:44











  • I've added another solution. See if you like it. Good luck forward.

    – Steen Harsted
    Mar 24 at 15:52











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%2f55323813%2fhow-to-set-different-color-scales-for-hexbin-based-on-data-groups%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














While this is not exactly what you asked for it might be a push in the right direction.



I don't think multiple color/cont scales are possible at the same time. You can change the color of the lines around the hexes, and increase line thickness.



First some sample data (please provide this yourself in the future)



library(tidyverse)
library(hexbin)

set.seed(1)

data_for_scatter_plot <-
crossing(
tibble(Trial =seq(1:100)),
tibble(Extra = seq(1:10)),
tribble(
~Gene, ~Log2FoldChange, ~length, ~TT_frequency, ~Type,
"ENSG00000007968", 1.928153, 24791, 0.05623008, "up_regulated",
"ENSG00000009724", 2.209263, 20711, 0.05842306, "down_regulated",
"ENSG00000010219", 1.794972, 53099, 0.08250626, "other_genes",
"ENSG00000053438", 3.815411, 2479 , 0.10851150, "up_regulate")) %>%
mutate(
Log2FoldChange = Log2FoldChange*0.001*Trial+rnorm(n=n(), mean=0, sd = 0.1),
TT_frequency = TT_frequency-0.00001*Trial+rnorm(n=n(), mean=0, sd = 0.005)
)


data_for_scatter_plot

# A tibble: 4,000 x 7
Trial Extra Gene Log2FoldChange length TT_frequency Type
<int> <int> <chr> <dbl> <dbl> <dbl> <chr>
1 1 1 ENSG00000007968 -0.0607 24791 0.0505 up_regulated
2 1 1 ENSG00000009724 0.0206 20711 0.0622 down_regulated
3 1 1 ENSG00000010219 -0.0818 53099 0.0853 other_genes
4 1 1 ENSG00000053438 0.163 2479 0.102 up_regulate
5 1 2 ENSG00000007968 0.0349 24791 0.0461 up_regulated
6 1 2 ENSG00000009724 -0.0798 20711 0.0614 down_regulated
7 1 2 ENSG00000010219 0.0505 53099 0.0754 other_genes
8 1 2 ENSG00000053438 0.0776 2479 0.117 up_regulate
9 1 3 ENSG00000007968 0.0595 24791 0.0654 up_regulated
10 1 3 ENSG00000009724 -0.0283 20711 0.0653 down_regulated
# ... with 3,990 more rows


Now the plot:



data_for_scatter_plot %>% 
ggplot(aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type)))+
geom_hex(size = 1)


enter image description here



I hope this helps.



---EDIT after comment---

I think a better solution for you is to facet. This will also make you able to distinguish overlapping groups



data_for_scatter_plot %>% 
ggplot(aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type)))+
geom_hex()+
facet_grid(cols = vars(factor(Type)))


enter image description here






share|improve this answer

























  • Thank you, I already use this solution, but I'm looking for more "looking good" one.

    – Elizabeth
    Mar 24 at 13:42











  • I don't think that wish is possible with geom_hex(). Is it important for you that it is geom_hex(), or have you already considered options such as faceting, fill, alpha?

    – Steen Harsted
    Mar 24 at 13:59











  • It's not important to me which package to use as long as I get the results that I want.

    – Elizabeth
    Mar 24 at 14:44











  • I've added another solution. See if you like it. Good luck forward.

    – Steen Harsted
    Mar 24 at 15:52















0














While this is not exactly what you asked for it might be a push in the right direction.



I don't think multiple color/cont scales are possible at the same time. You can change the color of the lines around the hexes, and increase line thickness.



First some sample data (please provide this yourself in the future)



library(tidyverse)
library(hexbin)

set.seed(1)

data_for_scatter_plot <-
crossing(
tibble(Trial =seq(1:100)),
tibble(Extra = seq(1:10)),
tribble(
~Gene, ~Log2FoldChange, ~length, ~TT_frequency, ~Type,
"ENSG00000007968", 1.928153, 24791, 0.05623008, "up_regulated",
"ENSG00000009724", 2.209263, 20711, 0.05842306, "down_regulated",
"ENSG00000010219", 1.794972, 53099, 0.08250626, "other_genes",
"ENSG00000053438", 3.815411, 2479 , 0.10851150, "up_regulate")) %>%
mutate(
Log2FoldChange = Log2FoldChange*0.001*Trial+rnorm(n=n(), mean=0, sd = 0.1),
TT_frequency = TT_frequency-0.00001*Trial+rnorm(n=n(), mean=0, sd = 0.005)
)


data_for_scatter_plot

# A tibble: 4,000 x 7
Trial Extra Gene Log2FoldChange length TT_frequency Type
<int> <int> <chr> <dbl> <dbl> <dbl> <chr>
1 1 1 ENSG00000007968 -0.0607 24791 0.0505 up_regulated
2 1 1 ENSG00000009724 0.0206 20711 0.0622 down_regulated
3 1 1 ENSG00000010219 -0.0818 53099 0.0853 other_genes
4 1 1 ENSG00000053438 0.163 2479 0.102 up_regulate
5 1 2 ENSG00000007968 0.0349 24791 0.0461 up_regulated
6 1 2 ENSG00000009724 -0.0798 20711 0.0614 down_regulated
7 1 2 ENSG00000010219 0.0505 53099 0.0754 other_genes
8 1 2 ENSG00000053438 0.0776 2479 0.117 up_regulate
9 1 3 ENSG00000007968 0.0595 24791 0.0654 up_regulated
10 1 3 ENSG00000009724 -0.0283 20711 0.0653 down_regulated
# ... with 3,990 more rows


Now the plot:



data_for_scatter_plot %>% 
ggplot(aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type)))+
geom_hex(size = 1)


enter image description here



I hope this helps.



---EDIT after comment---

I think a better solution for you is to facet. This will also make you able to distinguish overlapping groups



data_for_scatter_plot %>% 
ggplot(aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type)))+
geom_hex()+
facet_grid(cols = vars(factor(Type)))


enter image description here






share|improve this answer

























  • Thank you, I already use this solution, but I'm looking for more "looking good" one.

    – Elizabeth
    Mar 24 at 13:42











  • I don't think that wish is possible with geom_hex(). Is it important for you that it is geom_hex(), or have you already considered options such as faceting, fill, alpha?

    – Steen Harsted
    Mar 24 at 13:59











  • It's not important to me which package to use as long as I get the results that I want.

    – Elizabeth
    Mar 24 at 14:44











  • I've added another solution. See if you like it. Good luck forward.

    – Steen Harsted
    Mar 24 at 15:52













0












0








0







While this is not exactly what you asked for it might be a push in the right direction.



I don't think multiple color/cont scales are possible at the same time. You can change the color of the lines around the hexes, and increase line thickness.



First some sample data (please provide this yourself in the future)



library(tidyverse)
library(hexbin)

set.seed(1)

data_for_scatter_plot <-
crossing(
tibble(Trial =seq(1:100)),
tibble(Extra = seq(1:10)),
tribble(
~Gene, ~Log2FoldChange, ~length, ~TT_frequency, ~Type,
"ENSG00000007968", 1.928153, 24791, 0.05623008, "up_regulated",
"ENSG00000009724", 2.209263, 20711, 0.05842306, "down_regulated",
"ENSG00000010219", 1.794972, 53099, 0.08250626, "other_genes",
"ENSG00000053438", 3.815411, 2479 , 0.10851150, "up_regulate")) %>%
mutate(
Log2FoldChange = Log2FoldChange*0.001*Trial+rnorm(n=n(), mean=0, sd = 0.1),
TT_frequency = TT_frequency-0.00001*Trial+rnorm(n=n(), mean=0, sd = 0.005)
)


data_for_scatter_plot

# A tibble: 4,000 x 7
Trial Extra Gene Log2FoldChange length TT_frequency Type
<int> <int> <chr> <dbl> <dbl> <dbl> <chr>
1 1 1 ENSG00000007968 -0.0607 24791 0.0505 up_regulated
2 1 1 ENSG00000009724 0.0206 20711 0.0622 down_regulated
3 1 1 ENSG00000010219 -0.0818 53099 0.0853 other_genes
4 1 1 ENSG00000053438 0.163 2479 0.102 up_regulate
5 1 2 ENSG00000007968 0.0349 24791 0.0461 up_regulated
6 1 2 ENSG00000009724 -0.0798 20711 0.0614 down_regulated
7 1 2 ENSG00000010219 0.0505 53099 0.0754 other_genes
8 1 2 ENSG00000053438 0.0776 2479 0.117 up_regulate
9 1 3 ENSG00000007968 0.0595 24791 0.0654 up_regulated
10 1 3 ENSG00000009724 -0.0283 20711 0.0653 down_regulated
# ... with 3,990 more rows


Now the plot:



data_for_scatter_plot %>% 
ggplot(aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type)))+
geom_hex(size = 1)


enter image description here



I hope this helps.



---EDIT after comment---

I think a better solution for you is to facet. This will also make you able to distinguish overlapping groups



data_for_scatter_plot %>% 
ggplot(aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type)))+
geom_hex()+
facet_grid(cols = vars(factor(Type)))


enter image description here






share|improve this answer















While this is not exactly what you asked for it might be a push in the right direction.



I don't think multiple color/cont scales are possible at the same time. You can change the color of the lines around the hexes, and increase line thickness.



First some sample data (please provide this yourself in the future)



library(tidyverse)
library(hexbin)

set.seed(1)

data_for_scatter_plot <-
crossing(
tibble(Trial =seq(1:100)),
tibble(Extra = seq(1:10)),
tribble(
~Gene, ~Log2FoldChange, ~length, ~TT_frequency, ~Type,
"ENSG00000007968", 1.928153, 24791, 0.05623008, "up_regulated",
"ENSG00000009724", 2.209263, 20711, 0.05842306, "down_regulated",
"ENSG00000010219", 1.794972, 53099, 0.08250626, "other_genes",
"ENSG00000053438", 3.815411, 2479 , 0.10851150, "up_regulate")) %>%
mutate(
Log2FoldChange = Log2FoldChange*0.001*Trial+rnorm(n=n(), mean=0, sd = 0.1),
TT_frequency = TT_frequency-0.00001*Trial+rnorm(n=n(), mean=0, sd = 0.005)
)


data_for_scatter_plot

# A tibble: 4,000 x 7
Trial Extra Gene Log2FoldChange length TT_frequency Type
<int> <int> <chr> <dbl> <dbl> <dbl> <chr>
1 1 1 ENSG00000007968 -0.0607 24791 0.0505 up_regulated
2 1 1 ENSG00000009724 0.0206 20711 0.0622 down_regulated
3 1 1 ENSG00000010219 -0.0818 53099 0.0853 other_genes
4 1 1 ENSG00000053438 0.163 2479 0.102 up_regulate
5 1 2 ENSG00000007968 0.0349 24791 0.0461 up_regulated
6 1 2 ENSG00000009724 -0.0798 20711 0.0614 down_regulated
7 1 2 ENSG00000010219 0.0505 53099 0.0754 other_genes
8 1 2 ENSG00000053438 0.0776 2479 0.117 up_regulate
9 1 3 ENSG00000007968 0.0595 24791 0.0654 up_regulated
10 1 3 ENSG00000009724 -0.0283 20711 0.0653 down_regulated
# ... with 3,990 more rows


Now the plot:



data_for_scatter_plot %>% 
ggplot(aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type)))+
geom_hex(size = 1)


enter image description here



I hope this helps.



---EDIT after comment---

I think a better solution for you is to facet. This will also make you able to distinguish overlapping groups



data_for_scatter_plot %>% 
ggplot(aes(x=Log2FoldChange, y=TT_frequency, color=factor(Type)))+
geom_hex()+
facet_grid(cols = vars(factor(Type)))


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 24 at 15:51

























answered Mar 24 at 13:27









Steen HarstedSteen Harsted

358314




358314












  • Thank you, I already use this solution, but I'm looking for more "looking good" one.

    – Elizabeth
    Mar 24 at 13:42











  • I don't think that wish is possible with geom_hex(). Is it important for you that it is geom_hex(), or have you already considered options such as faceting, fill, alpha?

    – Steen Harsted
    Mar 24 at 13:59











  • It's not important to me which package to use as long as I get the results that I want.

    – Elizabeth
    Mar 24 at 14:44











  • I've added another solution. See if you like it. Good luck forward.

    – Steen Harsted
    Mar 24 at 15:52

















  • Thank you, I already use this solution, but I'm looking for more "looking good" one.

    – Elizabeth
    Mar 24 at 13:42











  • I don't think that wish is possible with geom_hex(). Is it important for you that it is geom_hex(), or have you already considered options such as faceting, fill, alpha?

    – Steen Harsted
    Mar 24 at 13:59











  • It's not important to me which package to use as long as I get the results that I want.

    – Elizabeth
    Mar 24 at 14:44











  • I've added another solution. See if you like it. Good luck forward.

    – Steen Harsted
    Mar 24 at 15:52
















Thank you, I already use this solution, but I'm looking for more "looking good" one.

– Elizabeth
Mar 24 at 13:42





Thank you, I already use this solution, but I'm looking for more "looking good" one.

– Elizabeth
Mar 24 at 13:42













I don't think that wish is possible with geom_hex(). Is it important for you that it is geom_hex(), or have you already considered options such as faceting, fill, alpha?

– Steen Harsted
Mar 24 at 13:59





I don't think that wish is possible with geom_hex(). Is it important for you that it is geom_hex(), or have you already considered options such as faceting, fill, alpha?

– Steen Harsted
Mar 24 at 13:59













It's not important to me which package to use as long as I get the results that I want.

– Elizabeth
Mar 24 at 14:44





It's not important to me which package to use as long as I get the results that I want.

– Elizabeth
Mar 24 at 14:44













I've added another solution. See if you like it. Good luck forward.

– Steen Harsted
Mar 24 at 15:52





I've added another solution. See if you like it. Good luck forward.

– Steen Harsted
Mar 24 at 15:52



















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%2f55323813%2fhow-to-set-different-color-scales-for-hexbin-based-on-data-groups%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

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript