小编Mel*_*eli的帖子

如何删除R中的levelplot刻度线边框?

levelplot函数使用方框的所有侧面绘制带有刻度线的热图。我想在x和y轴上保留刻度线,但删除顶部和右侧的刻度线。

如何删除框周围的右边框和顶部边框?

#fake data
data(mtcars)
cars.matrix <- as.matrix(mtcars[c(2:8)])
cars.corr <- cor(cars.matrix)

library('lattice')
levelplot(cars.corr, xlab="car stuff",ylab="Car Stuff", main="car stuff")
Run Code Online (Sandbox Code Playgroud)

汽车水平图图像

r border lattice levelplot

3
推荐指数
1
解决办法
2662
查看次数

你如何让 ggplot 标签同时使用标签 = abs 和标签 = 逗号?

我正在创建一个人口金字塔。我希望我的轴使用绝对值,以便我没有人口计数的负数。我还希望 x 轴上的刻度线用逗号格式化,这样它就会读取 30,000 而不是 30000。

我知道labels=comma会提供使用逗号的数字,我知道labels =abs会提供绝对值的数字。我如何结合这两个选项?

  #test data
   mfrawcensus <- data.frame(Age = factor(rep(x = 1:90, times = 2)), 
              Sex = rep(x = c("Females", "Males"), each = 90),
              Population = sample(x = 1:60000, size = 180))

 censuspop <-   ggplot(data=mfrawcensus,aes(x=Age,y=Population, fill=Sex)) + 
 geom_bar(data= subset(mfrawcensus,Sex=="Females"), stat="identity") + 
 geom_bar(data= subset(mfrawcensus,Sex=="Males"),
       mapping=aes(y=-Population),
       stat="identity",
       position="identity") + 
scale_y_continuous(labels=comma) + 
xlab("Age (years)")+ ylab("Population") + 
scale_x_discrete(breaks =seq(0,90,5), drop=FALSE)+   coord_flip(ylim=c(-55000,55000))
Run Code Online (Sandbox Code Playgroud)

我尝试在原始比例的基础上添加另一个比例以获得绝对值,但没有奏效。这是我的尝试:

   censuspyramid<-censuspop+theme_bw() +theme(legend.position="none")
  + ggtitle("a")+scale_y_continuous(labels=abs)
Run Code Online (Sandbox Code Playgroud)

r ggplot2 axis-labels

3
推荐指数
1
解决办法
1457
查看次数

标签 统计

r ×2

axis-labels ×1

border ×1

ggplot2 ×1

lattice ×1

levelplot ×1