由于ggplot2产生漂亮的彩色图形,但有时需要带有图案填充的黑白图形.我想知道如何做到这一点ggplot2,比如这段代码:
ggplot(diamonds, aes(cut, fill=cut)) + geom_bar()
Run Code Online (Sandbox Code Playgroud)
编辑
R图表的图案填充是否有任何功能?
这是情节的代码
library(ggplot2)
df <- data.frame(gp = factor(rep(letters[1:3], each = 10)), y = rnorm(30))
library(plyr)
ds <- ddply(df, .(gp), summarise, mean = mean(y), sd = sd(y))
ggplot(df, aes(x = gp, y = y)) +
geom_point() +
geom_point(data = ds, aes(y = mean), colour = 'red', size = 3)
Run Code Online (Sandbox Code Playgroud)

我希望有一个关于这个图的图例,它将识别数据值和平均值
Black point = Data
Red point = Mean.
Run Code Online (Sandbox Code Playgroud)
任何获得所需结果的指针都将受到高度赞赏.谢谢
我正在拟合glm模型R并且可以使用拟合模型在predict.glm(object=fm1, type="response")哪里获得响应尺度的预测值fm1.我想知道如何使用包中的augment函数以响应比例获得预测值broom.我的最低工作示例如下.
Dilution <- c(1/128, 1/64, 1/32, 1/16, 1/8, 1/4, 1/2, 1, 2, 4)
NoofPlates <- rep(x=5, times=10)
NoPositive <- c(0, 0, 2, 2, 3, 4, 5, 5, 5, 5)
Data <- data.frame(Dilution, NoofPlates, NoPositive)
fm1 <- glm(formula=NoPositive/NoofPlates~log(Dilution),
family=binomial("logit"), data=Data, weights=NoofPlates)
predict.glm(object=fm1, type="response")
# 1 2 3 4 5 6 7 8 9 10
# 0.02415120 0.07081045 0.19005716 0.41946465 0.68990944 0.87262421 0.95474066 0.98483820 0.99502511 0.99837891
library(broom)
broom::augment(x=fm1)
# …Run Code Online (Sandbox Code Playgroud) 我无法rstanarm在上R 3.5.3运行Ubuntu 18.04 LTS。我使用了以下命令:
install.packages("rstanarm")
Run Code Online (Sandbox Code Playgroud)
和
devtools::install_github("stan-dev/rstanarm", build_vignettes = FALSE)
Run Code Online (Sandbox Code Playgroud)
并且都引发以下错误:
Execution halted
Makevars:17: recipe for target 'stan_files/lm.cc' failed
make: *** [stan_files/lm.cc] Error 1
ERROR: compilation failed for package ‘rstanarm’
Run Code Online (Sandbox Code Playgroud)
sessionInfo
sessionInfo()
R version 3.5.3 (2019-03-11)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.2 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] …Run Code Online (Sandbox Code Playgroud) 对于IGF来自nlme库的数据,我收到此错误消息:
lme(conc ~ 1, data=IGF, random=~age|Lot)
Error in lme.formula(conc ~ 1, data = IGF, random = ~age | Lot) :
nlminb problem, convergence error code = 1
message = iteration limit reached without convergence (10)
Run Code Online (Sandbox Code Playgroud)
但是这个代码一切都很好
lme(conc ~ age, data=IGF)
Linear mixed-effects model fit by REML
Data: IGF
Log-restricted-likelihood: -297.1831
Fixed: conc ~ age
(Intercept) age
5.374974367 -0.002535021
Random effects:
Formula: ~age | Lot
Structure: General positive-definite
StdDev Corr
(Intercept) 0.082512196 (Intr)
age 0.008092173 -1
Residual …Run Code Online (Sandbox Code Playgroud) 我想知道<0.001如果p值小于0.001要使用的话,如何放置符号Sweave.任何帮助将受到高度赞赏.谢谢
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)
summary(lm.D9)$coef
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.8465 0.1557174 31.12368 4.185248e-17
group1 -0.1855 0.1557174 -1.19126 2.490232e-01
Run Code Online (Sandbox Code Playgroud)
期望的输出
Estimate Std. Error t value Pr(>|t|)
(Intercept) 4.8465 0.1557174 31.12368 <0.001
group1 -0.1855 0.1557174 -1.19126 0.249
Run Code Online (Sandbox Code Playgroud) 我想知道是否有一个函数可以ts直接用ggplot2 绘制对象.在过去,我使用以下策略,但现在它抛出错误.
set.seed(12345)
dat <- ts(data=runif(n=10, min=50, max=100), frequency = 4, start = c(1959, 2))
df <- data.frame(date=as.Date(time(dat)), Y=as.matrix(dat))
library(ggplot2)
ggplot(data=df, mapping=aes(x=date, y=Y))+geom_point()
Run Code Online (Sandbox Code Playgroud)
错误
Error in as.Date.default(time(dat)) :
do not know how to convert 'time(dat)' to class “Date”
Run Code Online (Sandbox Code Playgroud)
如果有人指导我如何直接绘制ts对象,我将非常感激ggplot2.在此先感谢您的帮助.
每当我使用时,将Ubuntu从14.04升级到16.04
knit2pdf(input="ABC.Rnw", quiet = TRUE)
Run Code Online (Sandbox Code Playgroud)
在RStudio Version 0.99.1197,我收到以下错误:
处理文件:./202Analysis.Rnw texi2dvi中的错误(file = file,pdf = TRUE,clean = clean,quiet = quiet,:'ABC.tex'上运行'texi2dvi'失败.消息:mkdir:无法创建目录'Yaseen/XYZ':没有这样的文件或目录/ usr/bin/texi2dvi:无法创建目录:Yaseen/XYZ
编辑
我的目录'Yaseen/XYZ STU'包含空格.删除这些空格后,一切正常.但是相同的代码在Ubuntu 14.04上运行良好.如何使这个(包含空格的目录名)适用于Ubuntu 16.04?
编辑2
这个链接说:
要构建PDF文档,您需要一个包含texi2dvi的TeX Live或texinfo版本(BEWARE:最近的TeX Live,以及一些texinfo RPM,不包括texi2dvi).
我用包中的fitdist函数拟合了正态分布fitdistrplus.使用denscomp,qqcomp,cdfcomp和ppcomp我们就可以绘制histogram against fitted density functions,theoretical quantiles against empirical ones,the empirical cumulative distribution against fitted distribution functions,和theoretical probabilities against empirical ones分别为如下.
set.seed(12345)
df <- rnorm(n=10, mean = 0, sd =1)
library(fitdistrplus)
fm1 <-fitdist(data = df, distr = "norm")
summary(fm1)
denscomp(ft = fm1, legendtext = "Normal")
Run Code Online (Sandbox Code Playgroud)
qqcomp(ft = fm1, legendtext = "Normal")
Run Code Online (Sandbox Code Playgroud)
cdfcomp(ft = fm1, legendtext = "Normal")
Run Code Online (Sandbox Code Playgroud)
ppcomp(ft = fm1, legendtext …Run Code Online (Sandbox Code Playgroud) 我从链接中借用了 R 代码并生成了下图:
使用相同的想法,我尝试使用我的数据如下:
library(tidyverse)
library(tidytable)
library(ggforce)
library(ggtext)
library(camcorder)
library(bibliometrix)
library(bibliometrixData)
data(management)
M <- metaTagExtraction(management, "AU_CO")
CO <-
tidytable(
Country = unlist(strsplit(M$AU_CO,";"))
, year = rep(M$PY, lengths(strsplit(M$AU_CO,";")))
, nAuPerArt = rep(lengths(strsplit(M$AU_CO,";")),lengths(strsplit(M$AU_CO,";")))
)
df0 <-
CO %>%
summarise.(
frequency = length(Country)
, frequencyFractionalized = sum(1/nAuPerArt)
, .by = c(Country, year)
) %>%
arrange.(Country, year)
df1 <-
df0 %>%
mutate.(
min_year = min(year)
, n_total = sum(frequency)
, .by = Country
) %>%
mutate.(Country = fct_reorder(Country, min_year)) %>%
count(Country, n_total, min_year, …Run Code Online (Sandbox Code Playgroud) r ×10
ggplot2 ×5
knitr ×2
broom ×1
distribution ×1
fitdistrplus ×1
glm ×1
installation ×1
latex ×1
plot ×1
predict ×1
rnw ×1
rstanarm ×1
rstudio ×1
stan ×1
statistics ×1
sweave ×1
tidyverse ×1
ubuntu-16.04 ×1
ubuntu-18.04 ×1