我想对 R 进行逆对数变换。
我熟悉常规的日志转换:
DF1$RT <- log(DF1$RT)
Run Code Online (Sandbox Code Playgroud)
但我不知道如何做相反的事情。
有人可以帮忙吗?
我有ggplot标题定位问题。当我使用hjust参数将标题向右滑动时,两行都会向左和向右滑动。我想要它们一个在另一个下面。drawlabel(),annototations对我的情况没有用,因为它们取决于 x 和 y 轴及其单位(日期、货币、公斤),这意味着每次我必须调整它们时。我想要独特的坐标系,无论我在绘制什么,我都可以轻松地将相同的位置用于不同的绘图。
下面显示了一个不受欢迎的代码示例。
set.seed(10)
df <- data.frame(x=1:10,y=round(rnorm(10)*1:10,2))
ggplot(df,aes(x=x,y=y))+
geom_line(size=0.75)+
labs(title = 'Here comes my title like that some words\nand my second line title')+
theme(
plot.title.position = 'plot',
plot.title = element_text(hjust = 0.075)
)
Run Code Online (Sandbox Code Playgroud)
不受欢迎的情节
合意的情节
我想xtable在Rnw文档中添加标题标题.这是代码.不幸的是,我无法在表格下添加标题.我已经尝试了\ caption {}函数,但它不会打印PDF.
我见过R:xtable标题(或注释),但它不适用于从R中的lm()函数创建的表.你有什么线索吗?
<<yoman,echo=FALSE,results=tex>>=
library(xtable)
pop5lm <- lm(mpg ~ wt, data=mtcars) #my linear model
print(xtable(pop5lm,
caption = c("Estimates of linear model for father Muro CB"),
label = "tab:one", digits = c(0,2, 2, 2,3)),
table.placement = "tbp",
caption.placement = "top")
@
Run Code Online (Sandbox Code Playgroud) 我一直收到这个错误,我不太清楚这意味着什么.我的所有变量名都是一致的,没有拼写错误.我在这里错过了什么吗?
代码
datNewagg <- aggregate (dataNew, by = list('x', 'y', 'z', 'a', 'ab'),
FUN = mean)
Run Code Online (Sandbox Code Playgroud)
产生错误
Error in aggregate.data.frame(datNew, by = list("x", "y", :
arguments must have same length
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用ggplot2制作温度趋势图.我不能用给定的斜率和截距绘制abline(它们是Sen Estimate用于趋势计算的结果).
df是我数据的子集.
df<- structure(list(Mean_Tmin = c(-6.85888797419416, -6.61640313272608,
-4.10521557474695, -3.33048575952967, -4.85158854541956, -6.90958783702363,
-5.4738307882025, -5.50757613208475, -3.34384859553843, -4.79079906097484,
-4.64407818570133, -4.17247075814977, -4.00324802670715, -2.92271555321199,
-4.26302362769172, -4.05299360203852, -3.65186880762282, -2.6784292470159,
-3.55928476504212, -3.26383609036539, -3.75455004498325, -4.01641178860892,
-4.95576810887431, -3.85043378628423, -3.39114296653151, -4.62589589895125,
-2.62611368991667, -3.60484580346817, -3.55386283157491, -3.76902382151618,
-3.05841501472943, -1.77644594829943, -4.01934355211525, -2.35357265559614,
-3.63012525456073, -4.61818077798782, -2.78669513101182, -1.87421430381448,
-2.99847245406934, -3.57236610167573, -3.56963065732644, -2.8243000106372,
-1.99565301030409, -3.3461888162997, -2.58940007000144, -3.19945356820737,
-5.37830757225912, -2.73135885451205, -1.88970245530541, -2.54034752481066,
-3.38038340627931, -3.13416288370415, -2.8610910675591, -2.89723228973215,
-2.3992604730445, -2.68507391337318, -2.92441273949878, -3.33097198455173,
-4.43334081889723, -4.53411741435393, -2.96651491236555), ID = c(1,
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …Run Code Online (Sandbox Code Playgroud) 我希望能够在R中创建包含以下数据的时间轴:
Label Date
A 7/7/2015 18:17
B 6/24/2015 10:42
C 6/23/2015 18:05
D 6/19/2015 17:35
E 6/16/2015 15:03
Run Code Online (Sandbox Code Playgroud)
像这样:--- A --- B ----------- CD ------ E
时间线只是水平线上的时间顺序日期,它们之间的时间差异.到目前为止,我无法使用ggplot2或时间轴包,因为我没有数值.
请提前帮助并谢谢!
编辑
我试过的代码
Label <- c("A", "B", "C", "D", "E")
Date <- c("7/7/2015 18:17", "6/24/2015 10:42", "6/23/2015 18:05", "6/19/2015 17:35", "6/16/2015 15:03")
dat <-data.frame(cbind(Label, Date))
dat$Date <- as.POSIXct(dat$Date, format="%m/%d/%Y %H:%M")
dat$y <- 0
library(ggplot2)
ggplot(dat, aes(Date, y))+ geom_point()
Run Code Online (Sandbox Code Playgroud) 我有一些如下数据:
num = list()
num[[1]] = c(1,2,3)
num[[2]] = c(4,5,6,7)
name = c("Alex", "Patrick")
Run Code Online (Sandbox Code Playgroud)
如何将其组合到一个看起来像这样的数据框?
Alex 1
Alex 2
Alex 3
Patrick 4
Patrick 5
Patrick 6
Patrick 7
Run Code Online (Sandbox Code Playgroud)
我很抱歉发布了一个很明显的问题.我已经广泛搜索并找不到答案,可能是因为我不知道如何很好地描述这个查询.
我正在使用ggplot2绘制图形,我想将算术符号放在图例标签中(或其他任何地方),例如"≥".我已经尝试过expression(x>=y)运行良好的编码线,但我不想在"≥"之前或之后使用该字符.例如,使用以下代码:
library(ggplot2)
mtcars$carb <- factor(mtcars$carb)
ggplot(mtcars, aes(wt, mpg, group=carb)) +
geom_point(aes(colour=carb), size=4) +
scale_colour_discrete(labels=c(expression(x>=y), "2", "3", "4", "6", "8"))
Run Code Online (Sandbox Code Playgroud)
我明白了
但我想要这个.
有没有办法做到这一点?
我正在尝试绘制一个简单的图表,DiagrammeR::mermaid它应该如下所示:
mermaid("
graph LR
A(Sample Text)
-->A
A-->B
B-->A
B-->
")
Run Code Online (Sandbox Code Playgroud)
显然(或不)-->A并且B-->代码不起作用。不可能有箭头从哪里来或从哪里来。
是否有一个简单的解决方法(空白节点?/不可见节点?)
我只是想开始使用 Rcpp,但无论我做什么,我都会遇到此错误。
> library("Rcpp")
> evalCpp("2 + 2")
"C:/rtools40/mingw64/bin/"g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-40~1.2/include" -DNDEBUG -I"//ad.uws.edu.au/dfshare/HomesBLK90946112/My Documents/R/win-library/4.0/Rcpp/include" -I"C:/Users/90946112/AppData/Local/Temp/Rtmp0Q7m7J/sourceCpp-x86_64-w64-mingw32-1.0.5" -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c file45bc2c9438a5.cpp -o file45bc2c9438a5.o
file45bc2c9438a5.cpp:1:10: fatal error: Rcpp.h: No such file or directory
#include <Rcpp.h>
^~~~~~~~
compilation terminated.
make: *** [C:/PROGRA~1/R/R-40~1.2/etc/x64/Makeconf:229: file45bc2c9438a5.o] Error 1
Error in sourceCpp(code = code, env = env, rebuild = rebuild, cacheDir = cacheDir, :
Error 1 occurred building shared library.
Run Code Online (Sandbox Code Playgroud)
为了检查一切设置是否正确,我运行了以下检查:
> find_rtools()
[1] TRUE
> find.package('Rcpp')
[1] "\\\\ad.uws.edu.au/dfshare/HomesBLK$/90946112/My Documents/R/win-library/4.0/Rcpp"
Run Code Online (Sandbox Code Playgroud)
和
> find_rtools()
[1] TRUE …Run Code Online (Sandbox Code Playgroud)