如何更改此图表上的x和y标签?
library(Sleuth2)
library(ggplot2)
discharge<-ex1221new$Discharge
area<-ex1221new$Area
nitrogen<-ex1221new$NO3
p <- ggplot(ex1221new, aes(discharge, area), main="Point")
p + geom_point(aes(size= nitrogen)) +
scale_area() +
opts(title = expression("Weighted Scatterplot of Watershed Area vs. Discharge and Nitrogen Levels (PPM)"),
subtitle="n=41")
Run Code Online (Sandbox Code Playgroud) 这个问题来自早期的问题及其答案.
首先是一些玩具数据:
df = read.table(text =
"School Year Value
A 1998 5
B 1999 10
C 2000 15
A 2000 7
B 2001 15
C 2002 20", sep = "", header = TRUE)
Run Code Online (Sandbox Code Playgroud)
最初的问题是如何为每所学校绘制价值年度线.答案或多或少对应于下面的p1和p2.但也要考虑p3.
library(ggplot2)
(p1 <- ggplot(data = df, aes(x = Year, y = Value, colour = School)) +
geom_line() + geom_point())
(p2 <- ggplot(data = df, aes(x = factor(Year), y = Value, colour = School)) +
geom_line(aes(group = School)) + geom_point())
(p3 <- ggplot(data = df, aes(x …Run Code Online (Sandbox Code Playgroud) ggplot2为屏幕/彩色打印生成精美的图形,但灰度背景和颜色在打印到灰度时会产生干扰.为了更好的可读性,我宁愿禁用灰色背景并使用产生不同灰度或不同填充笔划的颜色生成器来区分这些组.
我试图重新从GGPLOT2研讨会上图http://dl.dropbox.com/u/42707925/ggplot2/ggplot2slides.pdf.
在这种情况下,我试图生成示例5,抖动的数据点受闪避.当我运行代码时,这些点以正确的线为中心,但没有抖动.
这是代码直接来自演示文稿.
set.seed(12345)
hillest<-c(rep(1.1,100*4*3)+rnorm(100*4*3,sd=0.2),
rep(1.9,100*4*3)+rnorm(100*4*3,sd=0.2))
rep<-rep(1:100,4*3*2)
process<-rep(rep(c("Process 1","Process 2","Process 3","Process 4"),each=100),3*2)
memorypar<-rep(rep(c("0.1","0.2","0.3"),each=4*100),2)
tailindex<-rep(c("1.1","1.9"),each=3*4*100)
ex5<-data.frame(hillest=hillest,rep=rep,process=process,memorypar=memorypar, tailindex=tailindex)
stat_sum_df <- function(fun, geom="crossbar", ...) {stat_summary(fun.data=fun, geom=geom, ...) }
dodge <- position_dodge(width=0.9)
p<- ggplot(ex5,aes(x=tailindex ,y=hillest,color=memorypar))
p<- p + facet_wrap(~process,nrow=2) + geom_jitter(position=dodge) +geom_boxplot(position=dodge)
p
Run Code Online (Sandbox Code Playgroud) 我在Mac OS X 10.9.2上使用npm v1.4.4和node v0.10.25.
我最近升级了node和npm,现在npm install不再在node_modules中创建.bin目录了.
我删除了node_modules,npm install再次尝试,但从未创建目录和二进制文件.
有没有人知道为什么会这样?
这是我的package.json:
{
"name": "redacted",
"author": {},
"description": "redacted",
"dependencies": {
},
"devDependencies": {
"karma": "*",
"karma-coverage": "0.1.2",
"karma-junit-reporter": "*",
"karma-coffee-preprocessor": "~0.1",
"grunt": "^0.4.2",
"grunt-contrib-requirejs": "^0.4.3",
"grunt-contrib-concat": "^0.3.0",
"grunt-contrib-sass": "^0.7.2",
"grunt-contrib-htmlmin": "^0.2.0",
"grunt-contrib-cssmin": "^0.7.0",
"grunt-contrib-coffee": "^0.10.1",
"grunt-contrib-uglify": "^0.3.3",
"grunt-contrib-jst": "^0.5.1",
"grunt-contrib-qunit": "^0.4.0",
"grunt-contrib-jshint": "^0.8.0",
"grunt-contrib-watch": "^0.5.3",
"grunt-contrib-jasmine": "^0.6.1",
"grunt-contrib-compress": "^0.6.1",
"grunt-contrib-handlebars": "^0.6.1",
"grunt-contrib-less": "^0.9.0",
"grunt-contrib": "^0.9.0"
}
}
Run Code Online (Sandbox Code Playgroud) 我想在y轴上有漂亮的标签.例如,我更喜欢1000而不是1000.如何在ggplot中执行此操作?这是一个最小的例子:
x <- data.frame(a=c("a","b","c","d"), b=c(300,1000,2000,4000))
ggplot(x,aes(x=a, y=b))+
geom_point(size=4)
Run Code Online (Sandbox Code Playgroud)
谢谢你的任何提示.
标题很好地涵盖了它.
我有两个传说,涉及大小和颜色,并希望有一个,比如说,在图表的顶部和一个.
这是可能的,如果是的话,如何
TIA
我想在一个刻面的情节中添加一个方面标题作为条带ggplot2.我的MWE抛出一个错误.任何帮助将受到高度赞赏.谢谢
library(ggplot2)
library(gtable)
p <- ggplot(mtcars, aes(mpg, wt)) + geom_point()
p <- p + facet_grid(. ~ cyl)
# get gtable object
Plot1 <- ggplot_gtable(ggplot_build(p))
# add label for top strip
Plot1 <- gtable_add_rows(Plot1, Plot1$heights[[3]], 2)
Plot1 <- gtable_add_grob(Plot1,
list(rectGrob(gp = gpar(col = NA, fill = gray(0.5))),
textGrob("Cyl", gp = gpar(col = gray(1)))),
3, 4, 3, 10, name = paste(runif(2)))
# add margins
Plot1 <- gtable_add_rows(Plot1, unit(1/8, "line"), 2)
# draw it
grid.newpage()
print(grid.draw(Plot1))
Run Code Online (Sandbox Code Playgroud) 我正在研究data.frame看起来很有用的glm功能,所以我决定我会对模型矩阵的稀疏重复进行处理,这样我就可以把这个稀疏矩阵放到glmnet函数中了.但sparse.model.matrix看起来要从原始矩阵中删除一些行.知道为什么会这样,以及任何解决方案如何避免这种情况?代码如下:
> mm <- sparse.model.matrix(~clicks01+kl_tomek*bc1+hours+plec+1,
data = daneOst)
> dim(mm)
[1] 1253223 292
> dim(daneOst)
[1] 1258836 6
Run Code Online (Sandbox Code Playgroud) 我有以下代码将生成两个pdf文件,其中包含当前工作目录的图:
library(reshape)
library(ggplot2)
require(ggplot2)
source("http://gridextra.googlecode.com/svn/trunk/R/arrange.r")
data<-structure(list(Loci = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L,
21L, 22L, 23L, 24L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 35L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 52L, 44L, 45L,
46L, 47L, 48L, 49L, 50L, 51L, 53L, 54L, 55L, 56L, 57L, 58L, 59L,
60L, 61L, 62L), .Label = c("Baez", "Blue", "C147", "C204", "C21",
"C278_PT", "C294", "C316", "C485", …Run Code Online (Sandbox Code Playgroud)