C RUBY-ON-RAILS MYSQL ASP.NET DEVELOPMENT RUBY .NET LINUX SQL-SERVER REGEX WINDOWS ALGORITHM ECLIPSE VISUAL-STUDIO STRING SVN PERFORMANCE APACHE-FLEX UNIT-TESTING SECURITY LINQ UNIX MATH EMAIL OOP LANGUAGE-AGNOSTIC VB6 MSBUILD

# ggplot2 - how to assign geom_text with arrow icon to second yaxis scale

By : user2174070
Date : October 19 2020, 08:10 AM
I think the issue was by ths following , We can achieve what you're after if we scale values of ws such that they use the same range as conc, and then apply the inverse transformation inside sec_axis. The transformation that we are applying takes the form y = a + b * x, where y are the conc and x the ws measurements. The two scaling coefficients a and b are then obtained by solving a system of two linear equations:
code :
``````# Calculate scaling coefficients a and b
y1 <- min(mydf\$conc)
y2 <- max(mydf\$conc)
x1 <- min(mydf\$ws)
x2 <- max(mydf\$ws)
b <- (y2 - y1) / (x2 - x1)
a <- y1 - b * x1
``````
``````library(tidyverse)
mydf %>%
mutate(ws.scaled = a + b * ws) %>%
ggplot(aes(x = hour, y = conc)) +
geom_line(color = "black") +
geom_text(aes(x = hour, y = ws.scaled, angle = -wd + 90), label = "←", colour = "blue") +
scale_x_continuous(breaks = seq(0, 24, by=6), limits=c(0,24), name="Hour") +
scale_y_continuous(
breaks = seq(0,30,10),
name=  "Concentration",
sec.axis = sec_axis(~ (. - a) / b, name = "Wind Speed (m/s)")) +
theme(
axis.title.y = element_text(color = "black"),
axis.title.y.right = element_text(color = "black"))
``````

Share :

## scale bar and north arrow on map-ggplot2

By : user5945547
Date : March 29 2020, 07:55 AM
will help you A few years back I produced some code that could draw a scalebar (see also this post on r-sig-geo), this is the code I wrote back then. You could give it a go:
First some support functions:
code :
``````makeNiceNumber = function(num, num.pretty = 1) {
# Rounding provided by code from Maarten Plieger
return((round(num/10^(round(log10(num))-1))*(10^(round(log10(num))-1))))
}

createBoxPolygon = function(llcorner, width, height) {
relativeCoords = data.frame(c(0, 0, width, width, 0), c(0, height, height, 0, 0))
names(relativeCoords) = names(llcorner)
return(t(apply(relativeCoords, 1, function(x) llcorner + x)))
}
``````
``````addScaleBar = function(ggplot_obj, spatial_obj, attribute, addParams =
list()) {
addParamsDefaults = list(noBins = 5, xname = "x", yname = "y", unit = "m",
placement = "bottomright", sbLengthPct = 0.3, sbHeightvsWidth = 1/14)

scaleBarPolygon = do.call("rbind", lapply(0:(addParams[["noBins"]] - 1), function(n) {
dum = data.frame(createBoxPolygon(lowerLeftCornerScaleBar + c((n * widthBin), 0), widthBin, heightBin))
if(!(n + 1) %% 2 == 0) dum\$cat = "odd" else dum\$cat = "even"
return(dum)
}))
scaleBarPolygon[[attribute]] = min(spatial_obj[[attribute]])
textScaleBar[[attribute]] = min(spatial_obj[[attribute]])

return(ggplot_obj +
geom_polygon(data = subset(scaleBarPolygon, cat == "odd"), fill = "black", color = "black", legend = FALSE) +
geom_polygon(data = subset(scaleBarPolygon, cat == "even"), fill = "white", color = "black", legend = FALSE) +
geom_text(aes(label = label), color = "black", size = 6, data = textScaleBar, hjust = 0.5, vjust = 1.2, legend = FALSE))
}
``````
``````library(ggplot2)
library(sp)

data(meuse)
data(meuse.grid)
ggobj = ggplot(aes(x = x, y = y, color = zinc), data = meuse) + geom_point()
# Make sure to increase the graphic device a bit
``````

## assign a list of colour to the geom_text in ggplot2

By : user2811111
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , plot with assigned colors. , Try this minor change to the geom_text call:
code :
``````#plot
p <- ggplot(mtcars, aes(x=wt, y=mpg, label=rownames(mtcars)))
p + geom_text(colour=tmpC)
``````
``````p + geom_text(colour=rep(c('red','purple'), length.out = nrow(mtcars)))
``````

## Define yAxis value with two different yAxis scale highcharts

By : David Doan
Date : March 29 2020, 07:55 AM
I hope this helps . You should set alignTicks as false

## Conditionally assign geom_text placement for bar charts with ggplot2

By : user3060677
Date : March 29 2020, 07:55 AM
seems to work fine I am having an issue when making bar charts with mixed sign values in ggplot2. Take the following example:
code :
``````df <- data.frame(year = letters[1:3],
value = c(1, -1,-5)) %>%
mutate(text_location = ifelse(value < 0,0,value))

ggplot(df, aes(year, value)) +
geom_col() +
geom_text(aes(y = text_location,label = value), vjust = 0.0, size = 5)

``````

## Can't plot a scale bar or north arrow on ggplot2

By : Michael Z
Date : March 29 2020, 07:55 AM
I wish this help you The ggsn package is useful here. Without the GPS data, I can't execute all of your script, but this should add the north symbol and scale bar in reasonable locations, given the specified x and y limits.