Попробуйте вручную установить уровни фактора по оси x. Например:
library(ggplot2)
# Automatic levels
ggplot(mtcars, aes(factor(cyl))) + geom_bar()
[/g1]
# Manual levels
cyl_table <- table(mtcars$cyl)
cyl_levels <- names(cyl_table)[order(cyl_table)]
mtcars$cyl2 <- factor(mtcars$cyl, levels = cyl_levels)
# Just to be clear, the above line is no different than:
# mtcars$cyl2 <- factor(mtcars$cyl, levels = c("6","4","8"))
# You can manually set the levels in whatever order you please.
ggplot(mtcars, aes(cyl2)) + geom_bar()
[/g2]
Как указал Джеймс в своем Ответ reorder
- это идиоматический способ переупорядочения уровней факторов.
mtcars$cyl3 <- with(mtcars, reorder(cyl, cyl, function(x) -length(x)))
ggplot(mtcars, aes(cyl3)) + geom_bar()
[/g3]
У вас просто неправильные отступы. Все остальное работает отлично. Просто используйте этот код:
ip = input("Please enter an ip address with mask in CIDR format: ")
x = ip.split(".")
if "0/24" in x:
s = "."
s = s.join(x)
print(s[0:9] + "20 - " + s[0:9] + "191 is open range to use.")
else:
print("something else")