Comments (7)
Post a reproducible example please
from ggsn.
It looks like a mismatch between this package and coord_sf()
from ggplot2
.
library(ggplot2)
x = c(1000:2000)
y = c(100:200)
data <- data.frame( x = rep( x, each=1 ),
y = rep( y, length(x)),
z = rnorm( x ))
xlim.set<-range(data$x)
ylim.set<-range(data$y)
ggplot() +
geom_tile(data=data,
aes_string(x="x",
y="y",
fill="z")) +
ggsn::scalebar(location="bottomleft",
dist = .2, #km
x.min = xlim.set[1],
x.max = xlim.set[2],
y.min = ylim.set[1],
y.max = ylim.set[2],
dd2km = F,
dist_unit = "m",
st.bottom = F) +
coord_sf(datum = NA, #remove graticule per https://github.com/tidyverse/ggplot2/issues/2071
xlim=xlim.set,
ylim=ylim.set)
With coord_sf()
:
Without coord_sf()
:
from ggsn.
Try with higher values for st.dist
and height
.
from ggsn.
So I should rename this issue "work with coord_sf()" then.
from ggsn.
If there is a problem with scalebar()
and coord_sf()
, yes. However, you should provide a reproducible example and feedback for comments. The code you previously provided throw errors (Error in roundup(diff(xlim.set)/10) : could not find function "roundup"
and Error in FUN(X[[i]], ...) : object 'value' not found
) and does not has the code for the plots. Furthermore, you did not give any feedback about my comment, it did not work? Even after fixing the errors and writing the missing code for the plots, I got the expected behavior using height = .5
and st.dist = .7
.
Please provide a reproducible example a reply to comments to try to help you.
from ggsn.
I've updated the example to make it reproducible.
Manually adjusting height
and st.dist
will not work for my use case because I am generating multiple maps at once that potentially cover different extents and may have different amounts of aspect ratio modifications with coord_sf()
.
from ggsn.
Compare the plot using coord_sf()
with and without scalebar()
. I do not see conflicts between the functions. scalebar()
adds a scale bar with and height equal to a fraction hegiht
of the y axis, and the text is away of the scale bar by a fraction st.dist
of the y axis. If you generate multiple maps with different extents, height
and st.dist
will be a proportion relative to the each one of the particular extents (the proportion will be the same by the aboslute scale bar height and text distant will vary according to the extent).
ggplot() +
geom_tile(data=data,
aes_string(x="x",
y="y",
fill="z")) +
coord_sf(datum = NA,
xlim=xlim.set,
ylim=ylim.set)
ggplot() +
geom_tile(data=data,
aes_string(x="x",
y="y",
fill="z")) +
ggsn::scalebar(location="bottomleft",
dist = .2, #km
x.min = xlim.set[1],
x.max = xlim.set[2],
y.min = ylim.set[1],
y.max = ylim.set[2],
dd2km = F,
dist_unit = "m",
st.bottom = F,
st.dist = .12,
height = .1) +
coord_sf(datum = NA,
xlim=xlim.set,
ylim=ylim.set)
from ggsn.
Related Issues (20)
- Scalebar but no text on scaled up map HOT 2
- Custom positioning of scalebar HOT 3
- Error while installing on Centos HOT 2
- Compatibility with gganimate HOT 4
- Error in `st_geometry<-.data.frame`(`*tmp*`, value = NULL) : inherits(value, "sfc") || is.character(value) is not TRUE HOT 2
- scalebar() data arg secretly requires column names that start with 'lat' and 'long'
- scalebar() fails if 'data' contains columns other than latitude and longitude HOT 4
- scalebar() fails ungracefully if 'dist' is too large for the map
- scalebar() fails: In min(x) : no non-missing arguments to min; returning Inf HOT 3
- Option to change number of labels from 3 to 2 in scalebar
- scalebar() unit labels are incorrect if sf data object contains a column named "label"
- scalebar transform default should not be NULL (throws error)
- Scalebar with facet_wrap
- Error installing on R 4.02 HOT 1
- Error in library(ggsn) : there is no package called ‘ggsn’ HOT 2
- Support for terra rasters
- Change font
- Vulnerability to absence of retiring r-spatial packages HOT 4
- 'maptools' dependency is now retired HOT 2
- The scale bar doesn't appear on my drawing
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 ggsn.