Как добавить легенду в сюжет? [Дубликат]

public func isValidPassword() -> Bool {
    let passwordRegex = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z!@#$%^&*()\\-_=+{}|?>.<,:;~`’]{8,}$"
    return NSPredicate(format: "SELF MATCHES %@", passwordRegex).evaluate(with: self)
}

Если вам нужно быстрое исправление. Это проверка пароля с регулярным выражением. Скопируйте / вставьте файл помощника или расширения и используйте его.

45
задан nzcoops 25 May 2012 в 02:15
поделиться

3 ответа

Обновление: opts устарел. Вместо этого используйте theme, как описано в этом ответе.

Просто для того, чтобы развернуть ответ на кохске, так что это будет более полным для следующего человека, чтобы наткнуться на него.

mtcars$cyl <- factor(mtcars$cyl, labels=c("four","six","eight"))
library(gridExtra)

a <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + 
opts(legend.justification = c(0, 1), legend.position = c(0, 1), title="Legend is top left")
b <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + 
opts(legend.justification = c(1, 0), legend.position = c(1, 0), title="Legend is bottom right")
c <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + 
opts(legend.justification = c(0, 0), legend.position = c(0, 0), title="Legend is bottom left")
d <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + 
opts(legend.justification = c(1, 1), legend.position = c(1, 1), title="Legend is top right")

grid.arrange(a,b,c,d)

enter image description here [/g1]

43
ответ дан Claus Wilke 24 August 2018 в 04:00
поделиться

Чтобы расширить расширенные ответы выше, если вы хотите добавить отступы между легендой и пределами поля, используйте legend.box.margin:

# Positions legend at the bottom right, with 50 padding
# between the legend and the outside of the graph.
theme(legend.justification = c(1, 0), 
    legend.position = c(1, 0),
    legend.box.margin=margin(c(50,50,50,50)))

Это работает с последней версией ggplot2, который является v2.2.1 на момент написания.

6
ответ дан Contango 24 August 2018 в 04:00
поделиться

Я искал аналогичный ответ. Но обнаружил, что функция opts больше не является частью пакета ggplot2. После поиска еще немного времени, я обнаружил, что можно использовать theme для того, чтобы делать то же самое, что и опционы. Поэтому отредактируйте этот поток, чтобы минимизировать время.

Ниже приведен код, написанный nzcoops.

mtcars$cyl <- factor(mtcars$cyl, labels=c("four","six","eight"))
library(gridExtra)

a <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + labs(title = "Legend is top left") + 
theme(legend.justification = c(0, 1), legend.position = c(0, 1))

b <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + labs(title = "Legend is bottom right") +
theme(legend.justification = c(1, 0), legend.position = c(1, 0))

c <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + labs(title = "Legend is bottom left") +
theme(legend.justification = c(0, 0), legend.position = c(0, 0))

d <- ggplot(mtcars, aes(x=wt, y=mpg, colour=cyl)) + geom_point(aes(colour=cyl)) + labs(title = "Legend is top right") +
theme(legend.justification = c(1, 1), legend.position = c(1, 1))

grid.arrange(a,b,c,d)

Этот код даст точно такой же график.

37
ответ дан Kumar Manglam 24 August 2018 в 04:00
поделиться
Другие вопросы по тегам:

Похожие вопросы: