Vindaar / ggplotnim

A port of ggplot2 for Nim
https://vindaar.github.io/ggplotnim
MIT License
176 stars 15 forks source link

How to set fill color manually in geom_tile()? #87

Closed hffqyd closed 4 years ago

hffqyd commented 4 years ago

Thanks for your amazing tool. It was going all right when I did a heatmap-like plot using geom_tile(), but I cannot find a way to set the fill color manually? How can I do that in ggplotnim like scale_fill_manually() in ggplot2 package in R? Where can I find the answer? Thanks a lot for your help!

The code is below, it had been tested on Nim Version 1.2.0 [MacOSX: amd64]:

import ggplotnim, sequtils, seqmath

let
  pos = [1,2,3,1,2,3]
  name = ["a", "a", "a", "b", "b", "b"]
  n = [0, 1, 4, 4, 2, 3]
  df = seqsToDf(pos, name, n)

ggplot(df, aes("pos", "name")) + 
geom_tile(aes(fill = "n")) + 
geom_text(aes(text = "n"), size = some(25.0)) + 
scale_x_discrete() + 
scale_y_discrete() + 
ggsave("gg.pdf")
Vindaar commented 4 years ago

Hey!

Thanks for your amazing tool.

Thank you, glad you find it useful!

but I cannot find a way to set the fill color manually?

You cannot find a way to do it, because at the moment that functionality isn't exposed yet. It's straight forward to add though. I'll take a look at it today.

Vindaar commented 4 years ago

Once #88 is merged, this is possible as you would expect, via scale_fill_manual by providing a table, which maps all values found in the fill column to custom colors.

See the recipe here:

https://github.com/Vindaar/ggplotnim/blob/allowCustomFill/recipes.org#supplying-custom-colors-to-a-geom

Vindaar commented 4 years ago

Please let me know if this solves the issue for you (the PR is merged now and I released a new version).

hffqyd commented 4 years ago

After updated to v0.3.17, I tested the code in "recipes.org" , it worked and was what I want. Thanks for your very kindly help!

Vindaar commented 4 years ago

That's great to hear!