我有下一个问题。我使用的是R Studio,但我的y轴标签不完整。我有下一个代码:
cantidad_agua <- c(24.9, 143.7, 106.7, 5.1, 28.3, 12.3, 10.4, 7.9)
usos = c("Lavado de ropa","Riego de jardín","Baño personal","Cocina","Uso piscina","Lavado de trastes","Lavado de auto","Agua para beber")
barplot(cantidad_agua, main="Diagrama de barras de agua consumida en un día",
xlab="Cantidad de agua consumida(Gal)", names.arg=usos,
border="white", density=c(100, 90, 70, 50, 40, 30, 20, 10),
col="darkturquoise", las=2, horiz=TRUE)
答案 0 :(得分:2)
如果您想坚持使用基本图形并且不想切换到格子, ggplot2 ,或者无论如何,我建议您将par(mar = ...)
部署为在以上评论中由@MrFlick建议,或者你看看网格(与 gridBase 结合使用)。后者通过手动将视口定义为当前图形设备的子集,可以轻松绕过y轴标签的裁剪。例如,在随后的代码中,我创建了一个c("left", "bottom")
对齐的viewport
,它略微向右移动(x = .15
)并占据了x和图形窗口的85%和100% y方向,分别。
## load required packages
library(grid)
library(gridBase)
## start new graphics frame
plot.new()
## setup and push viewport
vp0 <- viewport(x = .15, y = 0, just = c("left", "bottom"),
width = .85, height = 1)
pushViewport(vp0)
## add barplot
par(new = TRUE, fig = gridFIG())
barplot(cantidad_agua,
main = "Diagrama de barras de \nagua consumida en un día",
xlab = "Cantidad de agua consumida(Gal)", names.arg = usos,
border = "white", density = c(100, 90, 70, 50, 40, 30, 20, 10),
col = "darkturquoise", las = 2, horiz = TRUE)
可以在grid.rect()
之后立即插入pushViewport
来检查新创建的viewport
的当前位置。请注意在插入实际数字之前使用par(new = TRUE, fig = gridFIG())
以防止barplot
打开新的图形设备。此外,请记住每次执行上述代码后运行dev.off()
,否则您迟早会遇到“数字余量太大”的错误。
答案 1 :(得分:0)
您可以使用ggplot2替代:
angular.module('AuthApp',[]).
config(function($routeProvider){
$routeProvider.
when('/about', {template:'partials/about.html'}).
when('/dashboard', {template:'partials/dashboard.html'}).
otherwise({redirectTo:'/home',template:'partials/home.html'})
});
function MainCtrl($scope,$location) {
$scope.setRoute = function(route){
$location.path(route);
}
}