-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mapPlot() should offer more control of axis labels #1707
Comments
I have this working in "develop" (see library(oce)
data("coastlineWorld")
proj <- "+proj=merc"
lonlim <- c(-20, 20)
latlim <- c(-20, 20)
if (!interactive()) png("1707a.png")
par(mfrow=c(2, 2), mar=c(2,2,1,1))
for (axisStyle in 1:4) {
mapPlot(coastlineWorld, longitudelim=lonlim, latitudelim=latlim,
col="tan", proj=proj, axisStyle=axisStyle, grid=c(5,5))
mtext(paste0("axisStyle=", axisStyle), cex=par("cex"))
}
if (!interactive()) dev.off() produces as below. |
@clayton33 since this stems from your #1706 issue, can I ask you to look at two things and comment here?
|
|
@clayton33 I added style 5, and I actually like it. What do you think? library(oce)
data("coastlineWorld")
proj <- "+proj=merc"
lonlim <- c(-20, 20)
latlim <- c(-20, 20)
if (!interactive()) png("1707a.png", width=7, height=5, res=120, unit="in")
par(mfrow=c(2, 3), mar=c(2,2,1,1))
for (axisStyle in 1:5) {
mapPlot(coastlineWorld, longitudelim=lonlim, latitudelim=latlim,
col="tan", proj=proj, axisStyle=axisStyle, grid=c(5,5))
mtext(paste0("axisStyle=", axisStyle), cex=par("cex"))
}
plot(0:1,0:1,xlab="",ylab="",axes=FALSE,type="n")
box()
text(0.5,0.5,"Test of\nmapPlot(...,axisType)\n(github issue 1707)")
if (!interactive()) dev.off() |
Looks nice :) |
Closing now. Thanks, @clayton33 |
Argument |
@chrisdane I'll take a look. I reopened the issue because open issues are a to-do list. NOTE: this won't make it to CRAN for 6 months to a year. We have a release that is being finalized on CRAN right now, and there are rules about frequent updates. |
I'll make it accept # Demo of why I will set up for las to be a 2-element vector,
# if the user wants more control.
library(oce)
data(coastlineWorld)
par(mfrow = c(2, 2))
for (las in 0:3) {
mapPlot(coastlineCut(coastlineWorld, -100),
longitudelim = c(-130, -55), latitudelim = c(35, 60),
las = las,
projection = "+proj=lcc +lat_0=30 +lat_1=60 +lon_0=-100", col = "gray"
)
mtext(sprintf("with las = %d", las), side = 3)
}
|
Actually, on second thought, I am going to make it require a two-element vector. Otherwise the user might get odd results like the bottom two panels in the plot above. Making it a two-element vector lets me write the docs to explain things, as provisionally below (in Roxygen2 format). #' @param las two-element axis label orientation, passed to [axis()]. The first
#' value is for the horizontal axis, and the second is for the vertical axis.
#' See [par()] for the meanings of the permitted values, 0, 1, 2 and 3. |
This shows the main part of the diff (not pushed to GH ... this is just a note to myself, really). grep -n "axis(side = " map.R
657: axis(side = 1, at = at, label = formatLonLat(longitude, "longitude", axisStyle = axisStyle), las = las[1])
679: axis(side = 2, at = at, label = formatLonLat(latitude, "latitude", axisStyle = axisStyle), las = las[2], line = line)
2558: axis(side = 1, at = axisLabels1$at[!skip], labels = FALSE, mgp = mgp)
2560: axis(side = 1, at = axisLabels1$at[!skip], labels = axisLabels1$value[!skip], las = las[1], mgp = mgp)
2578: axis(side = 2, at = axisLabels2$at[!skip], labels = FALSE, mgp = mgp)
2580: axis(side = 2, at = axisLabels2$at[!skip], labels = axisLabels2$value[!skip], las = las[2], mgp = mgp) |
I've updated oce so that I think @chrisdane -- if you can build oce from source, please do so and check to see if it seems useful, commenting here on what you find. If you like the results, I'll re-close the issue. # Demo of why I will set up for las to be a 2-element vector,
# if the user wants more control.
library(oce)
data(coastlineWorld)
png("las_%d.png")
par(mfrow = c(2, 2))
for (las1 in 0:3) {
for (las2 in 0:3) {
mapPlot(coastlineCut(coastlineWorld, -100),
longitudelim = c(-90, -50), latitudelim = c(35, 50),
las = c(las1, las2),
projection = "+proj=lcc +lat_0=40 +lat_1=45 +lon_0=-70", col = "gray"
)
label <- sprintf(
"with las = c(%d, %d) %s", las1, las2,
if (las1 == 0 && las2 == 0) " i.e. the default" else ""
)
mtext(label, side = 3, line = 0.5)
}
} |
Hi yes that works, thanks a lot. I am wondering if its possible and, if yes, more generic to pass all default parameters from Cheers, |
@chrisdane that's not really possible because we are talking about things that relate just to axes here. This is a general thing in R. Imagine some function Not only would this be confusing to the R system, it might be quite confusing to the user, also. One solution (used by oce and, I think, most R packages) is to name all the things that the user is allowed to control. Another approach is to let This explains why a lot of R functions (especially those for plotting) have a lot of parameters. And, sometimes, parameters hold parameters within themselves. An example you might know is the Sorry this is long-winded. The short answer is that using Make sense? |
Oh, I forgot to say: I think most users don't use Again, this is quite general, not related to Generally, and this goes for all my research work, I either go with simple defaults or I make a highly-tailored plot that works for the particular diagram I am making for a particular paper. |
Following up on discussion at #1706, maybe
mapPlot()
ought to have a new argument for controlling the labelling of axes.it could be called
axisStyle
, and take numeric values, perhapswith other varieties possibly coming later, perhaps with degrees and symbols (which might be quite ugly...)
The text was updated successfully, but these errors were encountered: