Comments (6)
(Link to the previous related issue)
First example
What do setting teh ymin and ymax asthetics do? As I understand it they are the y limits on the box that the text is placed into. ymin being a value on the plot I understand, but ymax =1 I don't?
That's correct: ymin
and ymax
set the y limits of the box. In the example from the previous issue, we want the box to extend from the top of the column to the top of the plot area, so ymax
was set to a value that allows enough 'headroom' over each bar to draw the text. Other values would also work:
library(ggplot2)
library(ggfittext)
ggplot(coffees, aes(x = coffee, y = proportion, label = ingredient, fill = ingredient)) +
geom_col(position = "dodge") +
geom_fit_text(aes(ymin = proportion, ymax = 0.6), position = "dodge", place = "bottom", grow = TRUE, reflow = TRUE)
Created on 2019-06-27 by the reprex package (v0.3.0)
geom_bar_text()
puts the text inside the bar so that you don't have to do this manual fiddling to set the 'headroom'.
Second example
The labels are different sizes and some are missing (presumably so small they could not be displayed.
I don't understand why this is happening if all the text is so similar?
library(ggfittext)
library(tidyverse)
pdat <- tribble(
~key, ~value, ~Name, ~value_label,
"key", 2.02942183, 1, 2.03,
"key", 1.27338181, 2, 1.27,
"key", 4.98740337, 3, 4.99,
"key", 1.43705013, 4, 1.44,
"key", 0.07890787, 5, 0.08,
"key", 2.34419584, 6, 2.34,
"key", 1.66281582, 7, 1.66,
"key", 2.28072594, 8, 2.28,
"key", 7.88383825, 9, 7.88,
"key", 1.40415457, 10, 1.40,
"key", 5.54193876, 11, 5.54,
"key", 0.16704932, 12, 0.17,
"key", 11.75658642, 13, 11.76,
"key", 1.13801370, 14, 1.14,
"key", 1.86561319, 15, 1.87,
"key", 0.77266434, 16, 0.77,
"key", 1.29502135, 17, 1.30,
"key", 1.56975971, 18, 1.57,
"key", 0.31144624, 19, 0.31,
"key", 2.38041735, 20, 2.38,
"key", 0.95595724, 21, 0.96
)
ggplot(pdat, aes(x = Name, y = value, fill = key, label = value_label)) +
geom_col() +
geom_fit_text(
aes(ymin = value_label, ymax = 13),
place = "bottom",
grow = FALSE,
reflow = TRUE
)
Created on 2019-06-27 by the reprex package (v0.3.0)You are correct that some of the labels are missing because they are too small to display. This threshold can be set with the min.size
option βΒ any text shrunk smaller than min.size
(expressed in pts) will be hidden. If min.size
is set to 0, no text will be hidden.
On the question of why some labels are different sizes, the answer is that some of them are actually much wider than others so need to be shrunk down. For example, let's compare the values on column 10 and column 13 as they are drawn by grid (the drawing layer that underpins ggplot2):
library(grid)
grid.newpage()
grid.text(label = "1.4", y = 0.6, gp = gpar(fontsize = 48))
grid.text(label = "11.76", y = 0.5, gp = gpar(fontsize = 48))
Created on 2019-06-27 by the reprex package (v0.3.0)
"11.76" is about twice the width of "1.4", which is why it needs to be shrunk to a much smaller font size to fit the width of the column.
from ggfittext.
OK. So I understand the intention.
I ran one more test that produced the attached plot. I changed the value_label column to contain the same value for each row. I would think the labels would all look the same since the columns should be the same width. The attached plot shows otherwise. I am wondering if there is something else that is influencing the font chosen?
Thanks for putting this package together!
Bill
from ggfittext.
Could you post the code that produced the plot? Looking at the plot I suspect ymax
is being set too low β it might be better if you used a value like 13 or 14.
from ggfittext.
Here is the code:
`
pdat <- tribble(
~key, ~value, ~Name, ~value_label,
"key", 2.02942183, 1, 2.03,
"key", 1.27338181, 2, 1.27,
"key", 4.98740337, 3, 4.99,
"key", 1.43705013, 4, 1.44,
"key", 0.07890787, 5, 0.08,
"key", 2.34419584, 6, 2.34,
"key", 1.66281582, 7, 1.66,
"key", 2.28072594, 8, 2.28,
"key", 7.88383825, 9, 7.88,
"key", 1.40415457, 10, 1.40,
"key", 5.54193876, 11, 5.54,
"key", 0.16704932, 12, 0.17,
"key", 11.75658642, 13, 11.76,
"key", 1.13801370, 14, 1.14,
"key", 1.86561319, 15, 1.87,
"key", 0.77266434, 16, 0.77,
"key", 1.29502135, 17, 1.30,
"key", 1.56975971, 18, 1.57,
"key", 0.31144624, 19, 0.31,
"key", 2.38041735, 20, 2.38,
"key", 0.95595724, 21, 0.96
)
pdat$value_label = 0.31
pdat$value_label <- as.character(pdat$value_label)
ggplot(pdat, aes(x = Name, y = value, fill = key, label = value_label)) +
geom_col() +
ggfittext::geom_fit_text(aes(ymin = value, ymax = 1),
place = "bottom",
grow = FALSE,
reflow = TRUE)
`
from ggfittext.
When I change the ggplot call above, I can get it to work. ymax was the issue:
`
ggplot(pdat, aes(x = Name, y = value, fill = key, label = value_label)) +
geom_col() +
ggfittext::geom_fit_text(aes(ymin = value, ymax = max(value) * 1.1),
place = "bottom",
grow = FALSE,
reflow = TRUE)
`
from ggfittext.
Glad to hear it. Let me know if you hit any more issues.
from ggfittext.
Related Issues (20)
- Export GeomFitText HOT 1
- Use ggfittext with coord_polar() HOT 1
- fill aesthetic produces warning even though it's needed for contrast = TRUE HOT 1
- Error in: if(shades::lightness(text$fill) < 50) on line 297 in geom_fit_text.R HOT 8
- Various issues HOT 1
- Plotted colours different to specified color in geom_bar_text() HOT 1
- Numbers don't move outside a small bar when using coord_flip() HOT 5
- Curve text around a path HOT 2
- Support for mapping the width and height values
- Error in grid::unit(x$height, "mm"): 'x' and 'units' must have length > 0 HOT 2
- Size as aestetic HOT 2
- Warning: Ignoring unknown aesthetics: label HOT 3
- fit text around polar coordinates HOT 2
- Fitting text with multiple font sizes HOT 4
- Add thousands separator to geom_bar_text output HOT 3
- fit text for pie plot HOT 1
- Constraining within a polygon, not just a geom_rect() or geom_tile()? HOT 4
- Integrating with `shadowtext::geom_shadowtext` or similar functionality? HOT 3
- geom_bar_text not work for my dataframe HOT 3
- Using geom_bar_text() to plot two labels HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ggfittext.